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>>> import json
2>>>
3>>> your_json = '["foo", {"bar":["baz", null, 1.0, 2]}]'
4>>> parsed = json.loads(your_json)
5>>> print(json.dumps(parsed, indent=4, sort_keys=True))
6[
7 "foo",
8 {
9 "bar": [
10 "baz",
11 null,
12 1.0,
13 2
14 ]
15 }
16]
17
1import json
2
3x = '{ "name":"John", "age":30, "city":"New York"}'
4y = json.loads(x)
5
6print(y["age"])
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{
2 "article": [
3
4 {
5 "id":"01",
6 "language": "JSON",
7 "edition": "first",
8 "author": "Derrick Mwiti"
9 },
10
11 {
12 "id":"02",
13 "language": "Python",
14 "edition": "second",
15 "author": "Derrick Mwiti"
16 }
17 ],
18
19 "blog":[
20 {
21 "name": "Datacamp",
22 "URL":"datacamp.com"
23 }
24 ]
25}
26