1import json
2
3x = '{ "name":"John", "age":30, "city":"New York"}'
4y = json.loads(x)
5
6print(y["age"])
1import json
2
3class Laptop:
4 name = 'My Laptop'
5 processor = 'Intel Core'
6
7#create object
8laptop1 = Laptop()
9laptop1.name = 'Dell Alienware'
10laptop1.processor = 'Intel Core i7'
11
12#convert to JSON string
13jsonStr = json.dumps(laptop1.__dict__)
14
15#print json string
16print(jsonStr)
1# a Python object (dict):
2x = {
3 "name": "John",
4 "age": 30,
5 "city": "New York"
6}
7
8# convert into JSON:
9y = json.dumps(x)