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))
1# Python program to read
2# json file
3
4
5import json
6
7# Opening JSON file
8f = open('data.json',)
9
10# returns JSON object as
11# a dictionary
12data = json.load(f)
13
14# Iterating through the json
15# list
16for i in data['emp_details']:
17 print(i)
18
19# Closing file
20f.close()
21
1import json
2
3json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
4'["foo", {"bar": ["baz", null, 1.0, 2]}]'
5
6print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
7{"a": 0, "b": 0, "c": 0}
8
1
2import json
3
4with open('path_to_file/person.json') as f:
5 data = json.load(f)
6
7# Output: {'name': 'Bob', 'languages': ['English', 'Fench']}
8print(data)
9
1print("Hello, World!") #Output: Hello, World!
2
3print(5+5) # Output:10
4
5x=10
6y=11
7print(x+y) #Output: 21