Nifty / Tools / Code from JSON

JSON to Python

Paste a JSON sample and get Python dataclasses for it, including nested types and arrays.

json-to-python
JSON sampleDrop a file here
Python
Loading…

Runs in your browser. Nothing you paste is uploaded or stored.

How to use the JSON to Python

  1. Paste a JSON sample on the left. Several examples in an array give better types.
  2. Name the top-level type.
  3. Copy the Python code.

Questions

Is my data uploaded anywhere?

No. The tool runs entirely in your browser. Nothing you paste or drop is sent to a server, logged or stored, so it's safe for API responses, config files and other private data.

How are optional fields detected?

If you paste an array of objects and a field is missing from some of them, it's marked optional. More sample data gives more accurate types.

Can I do this in VS Code?

Yes. Nifty Paste JSON as Code pastes JSON straight into a Python file as dataclasses.

Related tools