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?