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:
Paste 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.
Related Tools
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 → 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.
JSON → Java
Convert JSON to Java POJOs with Jackson @JsonProperty annotations, camelCase field names, List<T> for arrays, and generated getters/setters. Optional package declaration. 100% local.
JSON → C#
Convert JSON to C# classes with System.Text.Json [JsonPropertyName] attributes, PascalCase properties, List<T> for arrays, and optional namespace. Works in .NET 6 / 7 / 8 / 9. 100% local.
JSON → Rust
Convert JSON to Rust structs with #[derive(Serialize, Deserialize)]. snake_case field names, #[serde(rename)] for mismatched keys, Vec<T> for arrays, and reserved-keyword raw identifiers. 100% local.