JSON to Python Dataclass Converter
Paste a sample JSON object or array to generate matching Python @dataclass classes with type hints. Nested objects become their own named classes.
How to use it
Paste a representative JSON sample and click Generate. Field names that aren't valid Python identifiers (e.g. starting with a digit) are sanitized. Types are inferred from the single sample provided — this generates plain typed classes, not JSON (de)serialization logic.
Frequently Asked Questions
Does this handle JSON key → field name mapping for parsing?
No — it only generates the type shape (field names and hints). If a key isn't a valid Python identifier, the generated field name won't exactly match the original JSON key; you'd need a library like dataclasses-json or manual mapping to deserialize.
What if an array has mixed element types?
It becomes List[Union[T1, T2, ...]], listing every distinct element type observed.
What about null values?
A null field is typed Any, since a single sample can't tell you what other type it might hold.