JSON to Python
Generate Pydantic v2 models or Python dataclasses from JSON, with type hints, snake_case fields, aliases and Optional for missing keys.
JSON
Python
Pydantic or dataclass?
- Pydantic v2 checks types while loading and maps JSON keys to snake_case names with
alias(for examplereplyTo→reply_to). - dataclass needs no extra package. Each class gets a
from_dict()method that maps the keys and builds the nested classes. - Keys missing in some array items become
Optional[…] = None. Python keywords likeclassandtypeget a trailing underscore.
Load JSON into the model
# Pydantic
data = Root.model_validate_json(text)
# dataclass
import json
data = Root.from_dict(json.loads(text))Works with Python 3.9 and newer.
Smart type detection
Objects inside arrays are merged into one type, so a key that appears in only some items is still included (as optional). Names come from the keys, and plural keys become singular: comments → Comment. Whole numbers and decimals in the same field become a decimal type. Everything runs in your browser; your JSON is never uploaded.
More free tools
JSON to TypeScriptGenerate TS interfaces from sample data.JSON to GoGo structs with json tags from sample JSON.JSON to JavaJava records or POJOs with Jackson annotations.JSON to C#C# classes for System.Text.Json.JSON to RustSerde structs from sample JSON.JSON ViewerTree view, search, copy path. Handles huge files.JSON FormatterBeautify or minify JSON in one click.JSON ValidatorClear errors with exact line and column.