# JSON to types

> Paste a JSON sample and get typed interfaces instantly, in your browser, nothing uploaded.

JSON to types turns a sample JSON payload into typed model definitions by inferring the shape of the data — no schema, no annotations, and no API documentation required.

Also: json to typescript, json to types, generate typescript interface from json, json to interface, json to python, json to go struct, json to c# class, generate types from json.

## What it does

Paste a real response from an API you are consuming and get back the types you would otherwise hand-write. Nested objects are extracted into their own named models rather than being inlined, arrays are typed from their items, and fields that are absent or null in part of the sample are marked optional instead of being silently typed as required. The same tool emits TypeScript interfaces, Python Pydantic models, Go structs, Java records, PHP classes and C# records.

## When to use it

- You are integrating an API that has no OpenAPI spec and no published types.
- You want typed models for a response you just captured, without hand-writing them.
- You need the same payload typed for more than one language across services.
- You want to see how deeply nested a payload actually is before you model it.

## What you give it

| Input | Meaning |
| --- | --- |
| JSON sample | A representative response payload. Larger samples infer optionality more accurately. |
| Target language | TypeScript, Python, Go, Java, PHP or C#. |

## What you get back

| Output | Meaning |
| --- | --- |
| Type definitions | Named models for the payload and every nested object inside it. |
| Inferred shape summary | Field count, nesting depth, how many fields were marked optional, and the names of every type emitted. |
| Field breakdown | How many fields resolved to each kind: string, integer, number, boolean, array, object, null or unknown. |

## How it works

- Every value in the sample is classified into one of eight kinds: string, integer, number, boolean, array, object, null or unknown.
- Integers and floating-point numbers are distinguished, so a count does not become a decimal type.
- Each nested object becomes its own named model rather than an inline anonymous shape, which keeps deep payloads readable.
- A field is marked optional when its value is null, or when the key is missing from at least one item of an array — this is why a one-item sample under-reports optionality.

## Key terms

- **Type inference** — deriving a static type from an example value rather than from a declared schema. It describes the sample you provided, which is not necessarily every response the API can return.
- **Optional field** — a field that may be absent or null. Getting this wrong is the most common source of runtime errors when consuming an API, because the type says the value is always there and production disagrees.
- **Nesting depth** — how many levels of objects are stacked inside each other. Deep payloads are usually a sign the response is doing more than one job.

## Questions

### Does it only generate TypeScript?

No. The same JSON sample generates TypeScript interfaces, Python Pydantic models, Go structs, Java records, PHP classes or C# records — pick the target and the output changes.

### Why is a field marked optional when my API always returns it?

A field is marked optional when it was null in your sample, or when it was missing from at least one item in an array. If your sample was not representative, paste a larger one.

### Can it infer types from a JSON schema or OpenAPI file?

No — it reads a JSON value, not a schema. If you already have an OpenAPI definition, the OpenAPI visualizer and linter is the tool for that.

### Is my payload uploaded anywhere?

No. Inference runs entirely in your browser, so production payloads never leave the page.


## Privacy

Everything runs in your browser. The JSON you paste is never uploaded, never logged and never sent to a server, which is what makes it safe to paste a real production response.

## Links

- [Use the tool](https://www.postman.com/tools/json-to-types) — the interactive version of this page.
- [Postman Tools](https://www.postman.com/tools) — every free tool in this set.
- [API schema docs](https://learning.postman.com/docs/design-apis/specifications/overview/) — Postman documentation.
