Created
February 13, 2016 01:22
-
-
Save buchireddy/721edc283b46cb9265e3 to your computer and use it in GitHub Desktop.
Beautify a JSON file with python
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
import simplejson as json | |
obj = None | |
with open('file.json') as f: | |
obj = json.load(f) | |
outfile = open('file.json', "w") | |
outfile.write(json.dumps(obj, indent=4, sort_keys=True)) | |
outfile.close() |
@mathe999 This is an old script that I've written but I think there is an awesome jq
(https://stedolan.github.io/jq/) that I would recommend now. Can you try that/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, @buchireddy.
I don't know if I made any major mistakes but everytime I try to dump it it ends up dumping a string containing tabs and /n in one line.
Is there any way to avoid this?
Best regards, Mathe