How to Convert Python Dict to JSON?

The key-value pair structure of a Python dict is very similar to that of JSON, but there are differences in syntax and data types. If you need to visualize or process a python dict, you can first convert it to JSON and then use the powerful JSON editing and visualization features on JSON For You. The steps are as follows:

  1. Paste the original JSON string into the left editor;
  2. Click "Search Command" at the top, find "Python dict to JSON", and click to execute.

Since there are significant differences between python dict and JSON, JSON For You currently only supports simple text replacement, so converting complex dicts may fail.

FeaturePython DictionaryJSON
String QuotesSingle or double quotesDouble quotes only
Trailing CommasAllowedNot allowed
CommentsAllowed in code (not in dictionary literals)Not supported
Key TypeCan be any hashable typeString
Value TypeSupports tuples, sets, datetime, and custom objectsOnly supports strings, numbers, booleans, null, arrays, and objects

Example

Python dict:

{
    'name': 'John Doe',
    'age': 30,
    'is_student': False,
    'hobbies': ['reading', 'coding', 'hiking'],
    'address': {
        'street': '123 Main St',
        'city': 'Anytown'
    },
}

Converted JSON:

{
  "name": "John Doe",
  "age": 30,
  "is_student": false,
  "hobbies": ["reading", "coding", "hiking"],
  "address": {
    "street": "123 Main St",
    "city": "Anytown"
  }
}