Chrome Extension

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"}"
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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

json.dumps python method
Was this helpful?
0 Comments