Search code snippets, questions, articles...

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)
# -> "{"id": 1, "name": "Robert Downey Jr.", "nick_name": "Iron Man", "city": "New York"}"
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place.

Search Index Data (The code snippet can also be found with below search text)

json.dumps python method
Was this helpful?