1import json
2
3uglyjson = '{"firstnam":"James","surname":"Bond","mobile":["007-700-007","001-007-007-0007"]}'
4
5#json.load method converts JSON string to Python Object
6parsed = json.loads(uglyjson)
7
8print(json.dumps(parsed, indent=2, sort_keys=True))
1import json
2
3with open('file_to_load.json', 'r') as file:
4 data = json.load(file)
1
2import json
3
4with open('path_to_file/person.json') as f:
5 data = json.load(f)
1>>> import json
2>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
3['foo', {'bar': ['baz', None, 1.0, 2]}]
4>>> json.loads('"\\"foo\\bar"')
5'"foo\x08ar'
6>>> from io import StringIO
7>>> io = StringIO('["streaming API"]')
8>>> json.load(io)
9['streaming API']