bashANYjsonjqpretty-print
bash
jq . data.jsonThe most common CLI workflow for readable JSON.
Commands and patterns for compact JSON, human-readable formatting, stable sorting, and terminal-friendly inspection.
Make JSON readable in terminals, logs, and docs.
jq . data.jsonThe most common CLI workflow for readable JSON.
python -m json.tool data.jsonA portable fallback when `jq` is unavailable.
python - <<'PY'
import json
from pathlib import Path
p = Path('data.json')
obj = json.loads(p.read_text())
print(json.dumps(obj, indent=2, sort_keys=True))
PYStable key order is useful in reviews and version control.
Remove unnecessary whitespace for compact transport or embedding.
jq -c . data.jsonUseful for logs, payload fixtures, and embedding JSON in scripts.
python - <<'PY'
import json
from pathlib import Path
p = Path('data.json')
obj = json.loads(p.read_text())
print(json.dumps(obj, separators=(',', ':')))
PYThe `separators` option removes spaces after commas and colons.
curl -s https://api.example.com/users | jq .A practical workflow when inspecting REST responses.