Free · No sign-up · Runs in your browser

JSON to Python Dataclass Converter

Generate Python 3.10+ dataclasses from JSON samples with nested classes, list types, nullable fields and merged record shapes.

STEP 1

Start with your input

Edit the example or replace it with your own text.

How to use JSON to Python Dataclass Converter

  1. Paste one JSON object or a non-empty array of objects.
  2. Generate classes inferred from all supplied records, including fields missing in some samples.
  3. Review the annotations and renamed fields before using the Python code.

Infer a useful starting model

The converter examines every sample record, creates nested dataclasses, and combines different observed types with Python union annotations. Null or missing fields receive a None-compatible annotation and a default of None. Classes use keyword-only constructors so required and defaulted fields can coexist. Empty lists use Any because no element type can be inferred.

Generated types are not runtime validation

Dataclasses do not automatically parse dictionaries into nested instances or enforce annotations at runtime. Use a deliberate loading and validation layer. Non-Python field names are normalized and documented in comments; those comments do not implement JSON-key mapping. Numeric precision is limited by browser JSON parsing. The generated model describes samples, not every possible API response.

Example input

[{"user_id":1,"profile":{"name":"Ada"},"tags":["admin"]},{"user_id":2,"profile":null}]

Can I pass json.loads output directly into nested classes?

The root constructor accepts keyword arguments, but nested dictionaries are not automatically converted to dataclass instances. Add explicit deserialization logic.

Is input uploaded?

Processing takes place in your browser. This tool does not send your input or selected files to a conversion API.

Related tools and guides

Browse all developer tools