Repository: celery/celery

Issue:
Celery inspect output JSON serialization is broken
# Checklist
- [ ] I have verified that the issue exists against the `master` branch of Celery.
- [ ] This has already been asked to the [discussion group](https://groups.google.com/forum/#!forum/celery-users) first.
- [x] I have read the relevant section in the
  [contribution guide](http://docs.celeryproject.org/en/latest/contributing.html#other-bugs)
  on reporting bugs.
- [x] I have checked the [issues list](https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22)
  for similar or identical bug reports.
- [x] I have checked the [pull requests list](https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22)
  for existing proposed fixes.
- [ ] I have checked the [commit log](https://github.com/celery/celery/commits/master)
  to find out if the bug was already fixed in the master branch.
- [x] I have included all related issues and possible duplicate issues
  in this issue (If there are none, check this box anyway).

## Mandatory Debugging Information

- [ ] I have included the output of ``celery -A proj report`` in the issue.
    (if you are not able to do this, then at least specify the Celery
     version affected).
- [ ] I have verified that the issue exists against the `master` branch of Celery.
- [ ] I have included the contents of ``pip freeze`` in the issue.
- [ ] I have included all the versions of all the external dependencies required
  to reproduce this bug.

## Optional Debugging Information
- [ ] I have tried reproducing the issue on more than one Python version
  and/or implementation.
- [ ] I have tried reproducing the issue on more than one message broker and/or
  result backend.
- [ ] I have tried reproducing the issue on more than one version of the message
  broker and/or result backend.
- [ ] I have tried reproducing the issue on more than one operating system.
- [ ] I have tried reproducing the issue on more than one workers pool.
- [ ] I have tried reproducing the issue with autoscaling, retries,
  ETA/Countdown & rate limits disabled.
- [ ] I have tried reproducing the issue after downgrading
  and/or upgrading Celery and its dependencies.

## Environment & Settings
**Celery version**: 5.1.2 (sun-harmonics)

# Steps to Reproduce

Execute `celery -A proj inspect -j active`

# Expected Behavior
Valid JSON string is returned, like: 
```
{"worker-1": [], "worker-2": [], "worker-3": []}
```

# Actual Behavior
Command returns valid JSON in the first line, followed by double newline and some useless summary:
```
{"worker-1": [], "worker-2": [], "worker-3": []}

3 nodes online.
```
which makes the overall output an invalid JSON string.


Discussion:
Hey @adampl :wave:,
Thank you for opening an issue. We will get back to you as soon as we can.
Also, check out our [Open Collective](https://opencollective.com/celery) and consider backing us - every little helps!

We also offer priority support for our sponsors.
If you require immediate assistance please consider sponsoring us.

you probably want to use `--quiet` here:
edit: docs: https://docs.celeryproject.org/en/stable/reference/cli.html#cmdoption-celery-q
```console
(venv) jonas@ububox:~/workspace/celery$ celery -A tasks --quiet inspect --json active | jq
{
  "celery@ububox": []
}
```
if `--json` should imply the `--quiet` argument, we might want to change it this way. If the maintainers agree, I'd be happy to send this as a PR. Otherwise `--quiet` works well.
```diff
diff --git a/celery/bin/control.py b/celery/bin/control.py
index a13963a54..fbd3730c4 100644
--- a/celery/bin/control.py
+++ b/celery/bin/control.py
@@ -144,6 +144,8 @@ def inspect(ctx, action, timeout, destination, json, **kwargs):
 
     if json:
         ctx.obj.echo(dumps(replies))
+        return
+
     nodecount = len(replies)
     if not ctx.obj.quiet:
         ctx.obj.echo('\n{} {} online.'.format(

```
i think you should send  PR :)

Resolving patch:
diff --git a/celery/bin/control.py b/celery/bin/control.py
--- a/celery/bin/control.py
+++ b/celery/bin/control.py
@@ -144,6 +144,8 @@ def inspect(ctx, action, timeout, destination, json, **kwargs):
 
     if json:
         ctx.obj.echo(dumps(replies))
+        return
+
     nodecount = len(replies)
     if not ctx.obj.quiet:
         ctx.obj.echo('\n{} {} online.'.format(


Test patch: