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"}"

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

json.dumps python method
Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet