EN
Python - convert object to json
0 points
In this article, we would like to show you how to convert object to JSON in Python.
In this example, we use json.dumps()
method to convert object to the JSON.
xxxxxxxxxx
1
import json
2
3
object = {
4
"id": 2,
5
"name": "Tom",
6
"age": 25,
7
}
8
9
result = json.dumps(object)
10
11
print(result) # {"id": 2, "name": "Tom", "age": 25}
12
print(type(result)) # <class 'str'>
Output:
xxxxxxxxxx
1
{"id": 2, "name": "Tom", "age": 25}
2
<class 'str'>