-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialize_object_json.py
58 lines (34 loc) · 1.15 KB
/
serialize_object_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
# Serialize Python dict Object to JSON String
user = {"firstName": "Kathy", "lastName": "Wells"}
json_user = json.dumps(user)
print(json_user)
# Serialize Python list Object to JSON String
languages = ['Python', 'Java', 'C#', 'C++']
json_languages = json.dumps(languages)
print(json_languages)
# Serialize Python tuple Object to JSON String
skills = ('Web Development', 'Mobile Development', 'Agile')
json_skills = json.dumps(skills)
print(json_skills)
# Serialize Python string Object to JSON String
message = "Hello from toricode.com"
json_message = json.dumps(message)
print(json_message)
# Serialize Python int Object to JSON String
points = 7
json_points = json.dumps(points)
print(json_points)
# Serialize Python float Object to JSON String
price = 45.78
json_price = json.dumps(price)
print(json_price)
# Serialize Python True Object to JSON String
json_true = json.dumps(True)
print(json_true)
# Serialize Python False Object to JSON String
json_false = json.dumps(False)
print(json_false)
# Serialize Python None Object to JSON String
json_none = json.dumps(None)
print(json_none)