1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| import json
person = '{"name": "Bob", "languages": ["English", "Fench"]}' person_dict = json.loads(person)
with open('path_to_file/person.json') as f: data = json.load(f)
person_dict = {'name': 'Bob', 'age': 12, 'children': None } person_json = json.dumps(person_dict)
person_dict = {"name": "Bob", "languages": ["English", "Fench"], "married": True, "age": 32 }
with open('person.txt', 'w') as json_file: json.dump(person_dict, json_file)
person_string = '{"name": "Bob", "languages": "English", "numbers": [2, 1.6, null]}'
person_dict = json.loads(person_string)
print(json.dumps(person_dict, indent = 4, sort_keys=True))
|