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.
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
JSON → TypeScript
Generate named interfaces, with optionals and nullability inferred from every sample.
JSON → Zod
Generate a Zod schema, with formats, enums and optionals already applied.
JSON → JSON Schema
Generate a draft 2020-12 or draft-07 schema with $defs and required arrays.
JSON → Go
Generate Go structs with json tags, pointers for optional fields, and gofmt spacing.
JSON → C#
Generate C# classes or records with nullable annotations and serializer attributes.