JSON-Utils

JSON to Python

Generate Python dataclasses or Pydantic models from a JSON sample. Nested objects become their own classes, nulls and sometimes missing keys become Optional, and field ordering respects Python's rule that defaulted fields come last.

JSON
Python
Result will appear here
Ready. Press Generate or Ctrl+Enter.

How to use the JSON to Python

  1. Paste a JSON sample.
  2. Choose dataclasses or Pydantic and a root class name.
  3. Press Generate and copy the code.

Example

The notes key is null, so it becomes Optional in both styles.

{
  "name": "json-utils",
  "version": "1.0.0",
  "private": false,
  "tags": ["json", "tools"],
  "author": { "name": "Ada", "active": true },
  "score": 9.5,
  "notes": null
}

Frequently asked questions

Dataclasses or Pydantic?

Dataclasses are dependency free and good for internal data. Pydantic adds runtime validation, which suits API payloads.

What about keys that are not valid Python names?

They are sanitized into valid identifiers. With Pydantic you may still want Field(alias=...) for exact wire names; the generated names are noted in the code comments where they changed.