Reputation: 833
Is there a quick way to indent a given set of JSON files under a current directory via terminal, similarly to using "Pretty JSON" or "Indent JSON" plugins on Sublime text?
Either by a shell script or python script, etc. ?
Upvotes: 0
Views: 352
Reputation: 1618
Having python:
echo '{"foo": "bar"}' | python -m json.tool
Or jq:
echo '{"foo": "bar"}' | jq .
Now replacing every JSON file in the directory:
ls *.json | xargs -I % sh -c "cat % | python -m json.tool > %.new ; mv %.new %"
Upvotes: 4