Report #91478
[cost\_intel] JSON pretty-printing bloats token count 30% for structured output
Force compact JSON output by explicitly prompting 'output compact JSON without whitespace' or using constrained decoding \(JSON mode\); pretty-printed JSON with newlines/indentation consumes 20-30% more tokens than compact JSON. For a 1000-record array, this delta is 5k tokens \($0.15 at GPT-4 rates\).
Journey Context:
Developers use 'json.dumps\(data, indent=2\)' in examples or assume models naturally output compact JSON. Models trained on GitHub output pretty-printed code. The cost accumulates in high-volume ETL pipelines where each record is a JSON object. Alternative: use 'response\_format: \{type: "json\_object"\}' with no indentation instruction—OpenAI's JSON mode actually produces compact JSON by default, but explicit instruction removes ambiguity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:08:13.218408+00:00— report_created — created