Paste Python on the left and click "Convert" — we will turn it into JSONPaste Python code

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 just a string-replace. The converter understands what Python actually does at serialization time: single-quoted strings become double-quoted, tuples collapse to JSON arrays, set and frozenset become arrays too, datetime and date values come out as ISO-8601 strings per RFC 8259, Decimal drops to a number, and Enum members emit their .value. Nested objects are expanded in place, so a dataclass containing a list of other dataclasses round-trips cleanly.

Pydantic models (both v1 and v2) are supported. Field aliases set via Field(alias=...) rename keys in the output, Optional fields that are None are preserved as null, and Literal/Union types are emitted as their runtime value. Paste a whole module with several classes if you want — each one comes out as a top-level entry.

How to use it

Three steps. Works the same whether you paste a two-line dict or a 300-line module.

1

Paste your Python (or try the sample)

Drop your Python into the left editor as-is. A dict literal, a dataclass definition plus instance, a Pydantic model, or multiple classes with nested types — all fine. Hit Load Sample if you want to see what a realistic input looks like.

You do not need to strip imports or decorators. Leave the PEP 8 formatting, type hints, and any dataclass syntax alone.

2

Hit Convert

Click the green Convert button. The tool reads the Python, builds the object graph, and serializes it the same way json.dumps would — with indentation for readability. A short loading indicator shows while it runs.

3

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

Generate JSON examples for a README or API reference straight from the actual models you already have, so the docs cannot drift from the code.

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?

Non-serializable values (functions, generators, open sockets) come out as null rather than breaking the whole conversion. If the source has a syntax error, fix the obvious ones first — the parser is tolerant of style quirks but cannot run broken code.

Other tools you may need

Python to JSON is one piece of the puzzle. Here are the tools that pair well with it: