Converting Python dictionaries to and from JSON is easy with the json
package.
import json
def to_json(data):
'''Creates JSON from a Python dict'''
return json.dumps(data, indent=4, sort_keys=True)
def read_json(filename):
'''Reads JSON from a file, returns a Python dict'''
with open(filename, 'r') as f:
return json.load(f)