python
Convert Python Collections - List, Dict to JSON String
To convert Python Collections like Lists, Dictionaries to JSON String, you can use json.dumps() from the python json module.
import json
my_dict = {
"id": 1,
"name": "Robert Downey Jr.",
"nick_name": "Iron Man",
"city": "New York"
}
json_str = json.dumps(my_dict)
print(json_str)
# -> "{"id": 1, "name": "Robert Downey Jr.", "nick_name": "Iron Man", "city": "New York"}"
Was this helpful?
Similar Posts
- Convert JSON string to Python collections - like list, dictionaries
- Convert List of Tuples to JSON string in Python
- Convert a List of Strings to List of Integers in Python
- Convert all string values in a list to integers using python
- Methods to Convert a List to String using Python
- [Python] Use json.dumps() to pretty-print Python dicts
- [Python] Using comprehension expression to convert list of dictionaries to nested dictionary