← All Tools
JSON To Python Class Converter🔒 100% local
Convert JSON to Python dataclasses. Privacy-first, no server uploads, no tracking.
Writes Python @dataclass definitions from a JSON object, with the dataclass, field and typing imports at the top, snake_case attribute names, a type annotation for each key, and a default taken from the sample value. Each nested object becomes its own class declared above the one that uses it. Your JSON is parsed locally and the generated source is the only thing that leaves the tool, via your clipboard.
How to use it
- Paste a JSON object.
- Generate the classes with the Process button.
- Copy the code into a .py file; the closing comment points at pydantic if you want runtime validation instead.
Worked example
{"sku":"A-42","price":9.5,"stock":3}becomes# Python dataclasses generated from JSON
from dataclasses import dataclass, field
from typing import Any, Optional
@dataclass
class Root:
sku: str = "A-42"
price: float = 9.5
stock: int = 3
# Tip: paste into a .py file, or use pydantic BaseModel for runtime validation.Attribute names are converted to snake_case and each default is the value from your sample, so Root() builds a usable instance straight away.
When to use it
- Typing the response of an endpoint you have already captured as JSON.
- Turning a config file into a dataclass you can load and pass around instead of a loose dict.
- Getting consistent snake_case field names out of a camelCase payload.
What it does not do
- Only a JSON object is accepted at the root - an array or a scalar throws 'Provide a JSON object (dict), not an array or scalar.'
- A field that is an object in your sample is defaulted with field(default_factory=dict) even though its annotated type is the nested dataclass, so the generated default contradicts the type and needs editing.
- A null sample becomes Optional[Any] with = None, and nested classes only appear when the sample actually contains that object, so optional children of the payload are missing from the output.