generate json in python

Solutions on MaxInterview for generate json in python by the best coders in the world

showing results for - "generate json in python"
Emely
24 Jan 2016
1# JSON objects and JSON string objects can be created by reading a file directly 
2# with the json.load() and json.dump() functions.
3
4data_set = {"key1": [1, 2, 3], "key2": [4, 5, 6]}
5
6json_dump = json.dumps(data_set)
7
8print(json_dump)
9
10# String of JSON object
11
12OUTPUT
13{"key1": [1, 2, 3], "key2": [4, 5, 6]}
14
15json_object = json.loads(json_dump)
16
17print(json_object["key1"])
18
19# JSON object
20
21OUTPUT
22[1, 2, 3]