Python to JSON Converter
Paste Python dicts, dataclasses, or Pydantic models. Get clean JSON back.
What this tool does
If you have ever had to turn a Python dict or a dataclass into a JSON payload for an API call, a test fixture, or a bit of documentation, you know it gets tedious fast: quotes need flipping, True/False become true/false, None becomes null, and datetime/Decimal values have to be serialized by hand. Paste the Python here and get valid JSON back that matches exactly what json.dumps or a Pydantic .model_dump_json() call would produce, without you having to write the glue.
It is not a find-and-replace on quotes. The converter follows what json.dumps with a sensible custom encoder would produce: single quotes become double quotes, True, False and None become true, false and null, a tuple, set or frozenset becomes an array, and Enum members print their .value. JSON as defined in RFC 8259 has no date type, so datetime and date values are written as ISO-8601 text, and Decimal("249.99") becomes the number 249.99. A dataclass holding a list of other dataclasses is expanded all the way down.
Pydantic models from v1 and v2 work too. A field declared with Field(alias=...) uses the alias as its key, an Optional field holding None stays in the output as null, and Literal or Union fields show the value actually assigned. You can paste a whole models.py; every class that has an instance in the file gets a key at the root of the JSON.
How to use it
Three steps, the same for a five-line dict literal as for a models.py with a dozen dataclasses.
Paste your Python (or try the sample)
Paste the Python into the left editor unchanged, imports included. A dict literal, a @dataclass plus an instance, a Pydantic model or several classes that reference each other will all convert. Load Sample gives you an Order dataclass with Decimal prices, a datetime and a nested Address.
You do not need to strip imports or decorators. Leave the PEP 8 formatting, type hints, and any dataclass syntax alone.
Hit Convert
Press Convert. Your code goes to the backend, which works out the object values (keyword arguments, field(default_factory=list) defaults and all) and returns them as indented JSON. A "Converting..." overlay covers the editors while that request is in flight.
Copy the JSON
The right panel fills with pretty-printed JSON that is valid per the JSON spec. Copy it into your request body, your pytest fixture, your FastAPI OpenAPI example, or your config file.
When this actually comes in handy
API request fixtures
You have a Pydantic request model and need a sample JSON body for Postman, curl, or a Swagger example. Paste the model, get the JSON, done.
Pytest and unit-test data
Convert a dataclass instance from your test file into a JSON seed file for integration tests or snapshot comparisons, no custom encoder required.
Config file scaffolding
A settings dataclass with a few dozen fields becomes a ready-to-edit JSON template, so you are not hand-typing braces for the tenth time.
Syncing docs with code
Docs for a FastAPI or Flask endpoint need an example body. Paste the Pydantic model or dataclass, and the example you publish comes from the same definition the endpoint uses.
Common questions
Does it work with Pydantic v1 and v2?
Yes. Both are supported, including Field(alias=...), model_config, Field(default_factory=...), and nested models. Aliases rename keys in the output, matching what Pydantic itself would emit.
How are datetime, Decimal, and UUID handled?
datetime, date, and time come out as ISO-8601 strings. Decimal drops to a JSON number (no quotes). UUID becomes a standard hex string. bytes is base64-encoded. These match the conventions in the Python json module when you wire up a custom encoder.
What about Enum, Literal, and Optional?
Enum members emit their .value. Literal["a", "b"] emits the runtime string. Optional[X] fields that are None come through as JSON null rather than being dropped, so your output shape matches the type hints.
Can I paste a whole module with multiple classes?
Yes. Every top-level class with an instance in the module comes out as its own entry in the JSON. Nested dataclasses and Pydantic models are expanded in place, and inherited fields from parent classes are included.
Is my code stored anywhere?
The code is sent to the backend only to be converted. We do not log or persist it. As with any online tool, if what you are pasting is genuinely sensitive, give it a read-through first.
What if the Python has something weird: lambdas, generators, file handles?
Values JSON cannot hold, such as a lambda, a generator or an open file handle, come out as null so the rest of the object still converts. Nothing is executed, so code that would raise at runtime is not a problem, but a real syntax error (an unclosed bracket, tabs and spaces mixed inside a class body) can confuse the conversion, so tidy those up first.
Other tools you may need
With the JSON in hand, these take it back to Python classes, over to TypeScript, or through a validator: