Thursday, December 26, 2013

Write to a prettified JSON file in Python (with least number of lines of code)

import json

jsonData = ['foo', {'bar': ('baz', None, 1.0, 2)}]
with open('sample.json', 'w') as outfile:
    json.dump(jsonData, outfile, sort_keys= True, indent=4)

No comments:

Post a Comment