Python 3 - JSON

Updated: 2018-06-27

Pretty print JSON by python from command line:

$ cat data.json | python -m json.tool

Import

import json

Load From File

data = json.load(open("./data.json"))

Write To File

with open('./data.json', 'w') as fp:
    json.dump(data, fp, indent=2)

Dump As String

print(json.dumps(foo, indent=4))