Supply contrasting records
Use one object or a nonempty array containing only objects. All objects at a nested array location contribute to one element model; missing keys are discovered across those samples.
Type generation
Compare both sample records. Missing keys and explicit null produce different field defaults.
Parsed and generated in this browser. Input is not uploaded or stored.
Array samples define the element model Root. Pydantic load_models accepts either an object or an array.
2 classes · 2 nullable fields
JSON to Python turns representative API responses into a model draft. Include records with different keys: a single complete object cannot show which fields may be absent.
Choose standard-library dataclasses for typed containers or JSON to Pydantic for runtime parsing. Samples provide evidence about types, not a complete contract or business validation rules.
JSON to Python keeps an always-present nullable field required. A key absent from another sample instead receives a None default. These are different constructor and validation contracts.
Reserved words, punctuation and model methods need safe Python names. The generator retains the original spelling in dataclass metadata or Pydantic aliases, with deterministic suffixes for collisions.
Use one object or a nonempty array containing only objects. All objects at a nested array location contribute to one element model; missing keys are discovered across those samples.
Missing-key mode adds None only when a key is absent; all-optional mode permits omission everywhere. Date strings stay str unless ISO inference is selected. Decimal affects decimal or exponent tokens and numeric groups containing them.
Generation waits 350 ms after editing. Disable automatic mode for the Generate button or Ctrl/Cmd+Enter. Changes disable exports immediately. Clear and Example keep one undo snapshot of input, settings and source.
JSON to Python dataclass output imports only the standard library and places required fields before defaulted fields. Pydantic output targets exactly version 2.12.5. Child classes are declared before their parents, so Python 3.9 can import the entire file.
Plain integer groups use arbitrary-precision int. Decimal or exponent groups use float by default, including integers merged into that group; ordinary binary rounding applies. Decimal mode uses Decimal for those groups and its loader parses decimal tokens without a float intermediate, even inside Any containers.
ISO mode recognizes valid calendar dates and full timestamps with a timezone and at most six fractional second digits. All non-null strings at a position must have the same date kind. Invalid dates, naive timestamps and more precise strings stay str. Pydantic converts recognized strings; dataclasses do not.
Fields become ASCII snake_case. Keywords, leading underscores, model_* names and BaseModel methods are renamed. Empty keys, Unicode and control characters retain their aliases. Imported modules use private aliases to avoid collisions with class names such as Decimal or BaseModel.
Choose dataclass for a standard-library typed container when your code already handles parsing. JSON to Python also offers Pydantic when you need nested object construction and validation. Use its generated load_models helper and review the coercion and unknown-field rules.
The generated syntax targets Python 3.9 and later. It uses typing.Optional and orders dataclass defaults after required fields. Pydantic output is tested against 2.12.5; it is a fixed compatibility target, not a claim to use the latest release.
Yes. Nonempty nested objects create helper classes in the same file, with child classes first. Arrays merge all their elements. An array at the root defines the element class, and the Pydantic helper returns a list of those instances.
Yes, with your own explicit conversion code, but these generated dataclasses do not include that decoder. json.loads returns dictionaries and lists. You must map aliases and construct nested dataclasses yourself; metadata alone does not perform either step.
Keep aliases enabled. Pydantic Field(alias=...) reads the original JSON key; dataclasses store it as json_key metadata for your own adapter. Collision suffixes distinguish keys such as a-b and a_b. The Pydantic configuration avoids falling back to another field’s Python name.
Found an inference case to improve?
Use JSON to Python with missing keys, nulls and representative numbers, then test the exported source against your application’s parsing contract.