saidiraja opened a new issue, #66139:
URL: https://github.com/apache/airflow/issues/66139

   ### 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:
   
   ```bash
   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)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to