data = { "name": "foo", "age": 27 } with open("test.json", 'w', encoding='utf8') as outfile: json.dump(data, outfile, indent=2)