Python:JSON

From wiki
Revision as of 23:14, 21 December 2018 by Hdridder (talk | contribs)
Jump to navigation Jump to search
import json
Enable json functions. The json module is standard available (no installation needed)

Read a json file and return it as dict.

import json
with open(filename) as fh:
    data = json.load(fh)
json.dumps(dict, indent=4)
Convert a dict into a json string nicely structured. Indent each level with 4 spaces.
Can be used on other datatypes too.