Skip to content

CLI JSON output is polluted by logs and cannot be parsed by jq #66139

Open

Description

@saidiraja

Under which category would you file this issue?

Airflow Core

Apache Airflow version

3.2.0

What happened and how to reproduce it?

Issue Description

When running an Airflow CLI command with JSON output, logs are printed before the JSON payload.

For example:

airflow dags list -o json
prints Airflow/Alembic log lines before the JSON array starts.

This makes the output invalid JSON and breaks standard command-line tools such as jq.

## Steps to reproduce
1. Run:
airflow dags list -o json
2. Try to parse the output with jq:
airflow dags list -o json | jq
3. Or redirect the output to a file:
airflow dags list -o json > /tmp/output.json 2>&1
head -10 /tmp/output.json

## Observed behavior
The command outputs log lines before the JSON content, for example:
2026-04-30T01:14:29.770306Z [info] setup plugin alembic.autogenerate.schemas
2026-04-30T01:14:29.770491Z [info] setup plugin alembic.autogenerate.tables
2026-04-30T01:14:29.922347Z [warning] Could not import graphviz...
[{"dag_id": "SAFE_MODE_TEST_66104", ...}]
Because the output does not start with valid JSON, parsing fails:
jq: parse error: Invalid numeric literal at line 1, column 14
The failed pipe can also produce a Python BrokenPipeError traceback.

##Screenshots
##JSON parsing failure with jq

<img width="921" height="723" alt="Image" src="https://github.com/user-attachments/assets/652702b7-1e86-4c6c-a592-be8217e6e73f" />

##Raw JSON output polluted by logs

<img width="918" height="806" alt="Image" src="https://github.com/user-attachments/assets/7a0ae3d9-2dac-4755-8899-5cf89b3dbc3a" />

##Redirected output file starts with logs instead of JSON

<img width="937" height="860" alt="Image" src="https://github.com/user-attachments/assets/b537d35d-bf4a-48ae-8c07-d4276c2ca6e3" />

### What you think should happen instead?

When using `-o json`, the command output should be valid JSON that can be parsed directly by tools such as `jq`.

Logs and warnings should not be written to the same output stream as the JSON payload. They should either be suppressed for machine-readable output or written to stderr so stdout remains valid JSON.

### Operating System

Ubuntu 24.04.4 LTS (WSL2)

### Deployment

Virtualenv installation

### Apache Airflow Provider(s)

standard

### Versions of Apache Airflow Providers

apache-airflow-providers-common-compat==1.14.3
apache-airflow-providers-common-io==1.7.2
apache-airflow-providers-common-sql==1.34.0
apache-airflow-providers-smtp==2.4.5
apache-airflow-providers-standard==1.12.3

### Official Helm Chart version

Not Applicable

### Kubernetes Version

_No response_

### Helm Chart configuration

_No response_

### Docker Image customizations

_No response_

### Anything else?

This occurs consistently in my local Airflow 3.2.0 environment.

The issue affects scripting and automation because `-o json` output is expected to be machine-readable.

### Are you willing to submit PR?

- [x] Yes I am willing to submit a PR!

### Code of Conduct

- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

Activity

  1. added
    kind:bug
    needs-triage
    on Apr 30, 2026
  2. saidiraja commented on Apr 30, 2026

    @saidiraja
    ContributorAuthor

    Note: This issue is not specific to jq.

    Any tool expecting valid JSON fails because the output begins with log lines instead of a JSON array.

    Example:

    • Python json.load()
    • shell scripts parsing stdout

    This makes -o json unreliable for automation.

  3. FTS18 commented on May 1, 2026

    @FTS18

    Hey @saidiraja,

    I’ve opened a PR for this: #66223

    Handled it at the CLI entry level so logs go to stderr whenever -o json / -o yaml is used. This keeps stdout clean for tools like jq. Also added a regression test to lock this behavior in.

    Let me know what you think.

  4. bugraoz93 commented on May 1, 2026

    @bugraoz93
    Contributor

    Changes in CLI won't be needed we started moving already with AIP-94

    AIP-94: Migration Tooling from Airflow CLI to Airflow CTL (airflowctl)

    https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=382175838

    The CLI will use API and airflowctl under the hood. It will return pure JSON directly from airflowctl

  5. FTS18 commented on May 1, 2026

    @FTS18

    I've closed the PR to keep the roadmap clean. I'll take a look at AIP-94 and see if there are areas where I can contribute to the new migration tooling instead. Thanks!!!!

  6. saidiraja commented on May 3, 2026

    @saidiraja
    ContributorAuthor

    Thanks everyone for the discussion and clarification.

    That makes sense if the CLI is moving towards AIP-94 and will rely on airflowctl for structured output, then addressing this at the current CLI level may not be necessary.

    From my side, the main concern was ensuring that -o json is reliable for automation (e.g., jq, scripts, etc.). If the new tooling guarantees clean JSON output, that would fully address the issue.

    Happy to keep this open if it's still relevant for the transition period, or close it if it's considered covered by the ongoing migration.

    Let me know what you prefer.

  7. parkhojeong commented on May 4, 2026

    @parkhojeong
    Contributor

    thanks for your report. @saidiraja

    your issue description has image but preview does not work because of the markdown syntax.

    Image

    you can fix by adding ``` at the end of bash command
    Image

  8. parkhojeong commented on May 4, 2026

    @parkhojeong
    Contributor

    I posted the screenshot earlier

    Screenshots

    JSON parsing failure with jq

    Image

    Raw JSON output polluted by logs

    Image

    Redirected output file starts with logs instead of JSON

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:CLIkind:bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions