Data Format Conversions
Python Dict to JSON Converter
Workspace
Options
[1, 2, 3] instead of one item per line.
How to use this tool
- 1Paste a Python dict or list, or NAME = value assignments, or open a .py file.
- 2Read any notes about values JSON cannot hold (undefined, NaN, tuples…).
- 3Choose indentation and key sorting.
- 4Copy or download the .json file.
Frequently asked questions
No. A safe parser (like ast.literal_eval) reads only literal values. Function calls, variables and comprehensions are reported as errors with their line and column.
Tuples and sets become JSON arrays. Integer, float, True/False and None keys become strings ("1", "true", "null"), exactly as json.dumps does. Tuple keys cannot be represented and are reported.
float('nan') and float('inf') are not valid JSON, so they become null with a note. Python's json.dumps would write NaN, which most JSON parsers reject.
Yes. The output of print(my_dict) or repr() is a Python literal, so it converts directly.
Related tools
JSON to Python Converter
Convert JSON to a Python dict literal, or generate dataclasses, TypedDicts or Pydantic models from it.
JavaScript Object to JSON Converter
Convert JavaScript object and array literals to strict, valid JSON without running any code.
JSON Formatter
Beautify JSON with stable indentation and optional key sorting.
YAML Formatter & Validator
Format and validate YAML, convert YAML to JSON and JSON to YAML, with exact error lines.