Created
November 22, 2011 20:36
-
-
Save jperras/1386859 to your computer and use it in GitHub Desktop.
Mass prettification of JSON files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for f in `find . -path "*.json"`; do python -mjson.tool $f $f.output && mv $f.output $f; done |
Additionally, I had originally created find . -path "*.json" -print0 | xargs -0 -I FILENAME python -mjson.tool FILENAME FILENAME
, which would have worked fine. However, json.tool really doesn't like writing to the same file handle that it has opened for reading, and I didn't feel like rewriting it to be a bit smarter.
If anyone can see a way to do it with find
and xargs
(like I had originally intended) instead of going the bash script route, let me know!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sadly,
python -mjson.tool
seems to leave trailing whitespace on each reformatted line. Had to go in and clean that up withfind . -path "*.json" -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"
.