JSON to Python Dataclass
Generate a Python dataclass template with original-key mapping, exact integers and Decimal-aware JSON decoding.
This tool processes its input contents in your browser instead of sending them to a processing service. Page, asset and fixed usage-measurement requests are described on the Privacy page.
Generate a standard-library Python dataclass template and original-key decoder with arbitrary-size integers, Decimal parsing and conservative nested-container types.
How to use it
- 1Paste one JSON object and choose an uppercase Python class name.
- 2Generate and review field names, annotations and original-key mapping.
- 3Download the Python file and adapt the template to your real schema.
Example
- Input
- {"order-id":9007199254740993}
- Output
- order_id: int
Field excerpt from the generated class. The complete file includes from_json, from_dict and to_dict with the original order-id mapping.
What happens to your data
The example and generated Python code stay in this browser. The page does not execute the generated Python file.
Last updated November 2026
Start a Python model from a real JSON example without retyping its field names. Generate a top-level dataclass, conservative annotations and a decoder that maps renamed Python attributes back to the original JSON keys. The downloadable.py file includes an exact-key constructor and a Decimal-aware JSON loader. It is a template to review against your actual API contract.
How it works
Provide one JSON object and an uppercase class name. Valid Python attribute names are derived from the original keys. Punctuation, leading digits, reserved words and naming collisions receive deterministic alternatives. The generated from_dict and to_dict methods retain the exact original-key mapping, so an attribute such as order_id does not silently rename the external order-id field.
Integer tokens become Python int annotations; Python's JSON parser retains arbitrary-size integers. Decimal or exponent tokens use Decimal in the generated loader instead of binary floating-point. Nested objects and arrays remain dict[str,Any] and list[Any], rather than pretending that one example proves all nested shapes. Null uses Any. The decoder rejects duplicate JSON properties, nonstandard numeric constants and a different set of top-level keys. It does not enforce the annotated value types at runtime.
One example cannot establish required fields across every response, nullable alternatives, date semantics or a complete production schema. Review and adapt the template before integrating it. Decimal values in to_dict remain Decimal objects; this tool does not add a serializer that silently converts them back to floats. The generated file targets Python 3.10or later and uses standard-library modules only. Input is limited to128 KiB,5,000 values and200 top-level fields. No Python code is run by this page.
Common use cases
- Create a reviewable model for an API sample with punctuation in its keys.
- Keep long order IDs and exact decimal amounts during Python JSON decoding.
- Produce an explicit starting point for tests without adding a model framework.
Frequently asked questions
Does it generate nested dataclasses?+
No. Nested containers remain dictionaries or lists with Any values. This deliberate boundary avoids guessing a complete nested schema from one sample.
Are annotations runtime validation?+
No. The generated decoder checks the exact key set, duplicate keys and JSON syntax, but does not validate every value against the annotation.
Are decimal values rounded?+
The generated from_json loader uses Decimal for fractional/exponent tokens and Python int for integers. to_dict retains those objects.
Does the page execute Python?+
No. It generates text in the browser. Review the complete file before running or importing it in your own environment.
Standards and limitations
Related tools
cURL to Fetch
Convert a supported literal cURL request to reviewable JavaScript Fetch code without sending the request.
JSON to Go Struct
Generate an exported Go struct from a JSON example, with exact JSON tags, nested fields and conservative types for uncertain values.
JSON Schema Example Generator
Create one deterministic JSON example from a documented JSON Schema subset, with clear errors for unsupported constraints and no remote references.
JSONPath Extractor
Extract JSON values by child property, array index or wildcard. Export each match with its normalized path and original numeric spelling.