JSON to Python Dataclass
Paste a JSON object or array and generate a typed Python @dataclass with inferred field types. Runs entirely in your browser.
🔒 This tool runs entirely in your browser. Your files are never uploaded to a server.
How the JSON to dataclass converter works
- Paste a JSON object (or array of objects) - a sample loads automatically.
- Set the class name you'd like the generated dataclass to use.
- Copy the generated Python code, complete with typing imports.
FAQ
How does the tool infer Python types?
Strings become str, whole numbers become int, decimals become float, booleans become bool, arrays become List[...] based on their first element, and nested objects become Dict[str, Any].
What happens if I paste an array of objects?
The tool uses the first object in the array to infer the dataclass fields - useful for API responses that return a list of records.
Are nested objects converted into their own dataclasses?
No - nested objects are typed as Dict[str, Any] to keep the output simple. You can copy the output and manually break out nested classes if needed.
What if a field is null in my JSON?
Null values are typed as Optional[str] as a safe default, since the actual type can't be inferred from a single null value.
How we compare
| Feature | Online Tool Store | Hand-typing fields | Pydantic codegen CLI |
|---|---|---|---|
| No install required | ✓ | ✓ | ✗ |
| Automatic type inference | ✓ | ✗ | ✓ |
| Works entirely in the browser | ✓ | ✓ | ✗ |
Handy for quickly scaffolding a dataclass from a sample API response instead of writing field definitions by hand.