JSON to Python Dataclass Converter
Convert JSON to Python @dataclass definitions with typed fields. snake_case field names, nested classes, List[T] for arrays, and JSON-key alias comments. 100% local.
Last updated:
CommentsPaste JSON to generate Python @dataclass definitions with typed fields (snake_case), nested classes, List[T] for arrays, and JSON-key alias comments. Ready for stdlib json.loads() with dacite, or easy to convert to pydantic. 100% local.
Tips & Best Practices
- ▸For strict runtime validation, swap @dataclass for pydantic.BaseModel — the field types transfer directly.
- ▸Provide a comprehensive sample: null values become Any, so any field that's null in the sample won't be tightly typed.
- ▸For deep JSON, the tool generates one dataclass per nested object with PascalCase names derived from the field name.
Frequently Asked Questions
Why dataclass and not TypedDict or Pydantic?
Dataclasses are stdlib (no third-party dependency) and cover the 95% case for API model shapes. The output is easy to adapt: swap @dataclass for pydantic.BaseModel, or paste into a TypedDict, and it keeps working.
How are field names converted?
JSON keys are converted to Python snake_case (e.g. userName → user_name). A trailing comment shows the original JSON key so tools like dacite or pydantic aliases can round-trip.
How are nested objects handled?
Each nested object becomes its own @dataclass named after the field (PascalCased). Arrays become List[T] where T is inferred from the first element.
Is my JSON uploaded anywhere?
No. All conversion runs locally in your browser as client-side JavaScript.
Try Next
JSON → PHP
Convert JSON to PHP 7.4+ classes with typed properties. Generates one class per nested object, phpdoc @var array<T> for typed arrays, and camelCase property names. 100% local.
Related Tools
JSON → CSV
Convert an array of JSON objects to CSV online. Headers are inferred automatically from all keys across records.
CSV → JSON
Convert CSV data to a JSON array of objects online. Auto-detects delimiter and quotes, preserves numeric types when requested.
Number Base
Convert numbers between binary, octal, decimal, and hexadecimal. Supports arbitrarily large integers using BigInt.
JSON → TypeScript
Convert JSON to TypeScript interfaces instantly. Generate strongly-typed TS types from any JSON sample.
JSON → Go
Convert JSON to Go structs online. Generates idiomatic Go structs with proper json tags and PascalCase field names.
JSON → YAML
Convert JSON to YAML online. Preserve structure, comments-free, and ready to paste into Kubernetes or CI configs.