L LocalUse Source

JSON to Python

Paste a JSON response and get Pydantic v2 models or plain dataclasses. Keys are converted to snake_case with the original preserved as an alias, and fields are ordered so the result imports without a TypeError.

Root type name
Style
JSON
Output

Output appears here as you type.

Runs entirely in your browser. Nothing you paste here is uploaded or stored.

Questions

Is my JSON uploaded anywhere?

No. Inference and code generation run entirely in your browser. Nothing is sent to a server, so pasting a real API response with customer data or internal URLs is safe.

Should I paste one object or an array of them?

An array, whenever you have one. Every element is merged into a single shape, so a field that is missing from some records becomes optional and a field that is sometimes null becomes nullable. One object can only ever tell the generator that everything is required.

Why does this produce different types than other converters?

Because every element of the array is merged before anything is generated. A converter that reads only the first record cannot know that a field is missing from later ones, or that it is sometimes null, so it emits a plain non-nullable type. In a statically typed language that is not a cosmetic difference: it is the line between a clean decode and a nil dereference at runtime.

Pydantic or dataclasses?

Pydantic if you are parsing JSON, because it validates the payload and applies the field aliases for you. Dataclasses if you only want a typed container and are decoding some other way - they are stdlib, with no dependency, but they do not map JSON keys or check types at all.

Why were my fields reordered?

A dataclass cannot declare a field with a default before one without; Python raises "non-default argument follows default argument" when the module is imported. Optional fields carry a None default, so they are emitted after the required ones. Knowing which fields are genuinely optional is what makes that possible.

What happened to my _id field?

It becomes id with alias="_id". Pydantic treats a leading underscore as a private attribute and rejects the model outright, so the Mongo-style key has to be renamed - the alias keeps parsing the original document unchanged.

More code generation tools