File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ import json
2+
3+ # Serialize Python dict Object to JSON String
4+ user = {"firstName": "Kathy", "lastName": "Wells"}
5+
6+ json_user = json.dumps(user)
7+
8+ print(json_user)
9+
10+ # Serialize Python list Object to JSON String
11+ languages = ['Python', 'Java', 'C#', 'C++']
12+
13+ json_languages = json.dumps(languages)
14+
15+ print(json_languages)
16+
17+ # Serialize Python tuple Object to JSON String
18+ skills = ('Web Development', 'Mobile Development', 'Agile')
19+
20+ json_skills = json.dumps(skills)
21+
22+ print(json_skills)
23+
24+ # Serialize Python string Object to JSON String
25+ message = "Hello from toricode.com"
26+
27+ json_message = json.dumps(message)
28+
29+ print(json_message)
30+
31+ # Serialize Python int Object to JSON String
32+ points = 7
33+
34+ json_points = json.dumps(points)
35+
36+ print(json_points)
37+
38+ # Serialize Python float Object to JSON String
39+ price = 45.78
40+
41+ json_price = json.dumps(price)
42+
43+ print(json_price)
44+
45+ # Serialize Python True Object to JSON String
46+ json_true = json.dumps(True)
47+
48+ print(json_true)
49+
50+ # Serialize Python False Object to JSON String
51+ json_false = json.dumps(False)
52+
53+ print(json_false)
54+
55+ # Serialize Python None Object to JSON String
56+ json_none = json.dumps(None)
57+
58+ print(json_none)
You can’t perform that action at this time.
0 commit comments