JSON Tool

JSON to TypeScript – Generate Interfaces from Sample Payloads

Paste any JSON response and get accurate TypeScript interfaces — nested types named, mixed arrays converted to union types, and zero uploads.

Root:
JSON Input
TypeScript Output
TypeScript types will appear here...

Nested Type Inference

Each nested object becomes its own named interface, so you can re-use sub-types across your app.

Mixed-Type Arrays

Heterogeneous arrays become union types like (string | number)[] — accurate, not lazy any[].

Privacy by Default

Generation runs in your browser — paste production payloads without worrying about uploads.

Hand-picked tools that pair well with this one.

Why Generate Types From JSON?

Hand-typing TypeScript interfaces from a 200-line API response is tedious and error-prone. Our generator infers accurate types straight from a real payload — capturing every nested object, every optional field, and every mixed-type array your runtime actually sees.

Smart Inference

Each nested object becomes its own named interface, arrays of objects with varying shapes get merged into a single type, and heterogeneous arrays render as union types — never lazy any[].

Key Features

Named Nested Interfaces Sub-objects get their own interface declarations — reusable across your codebase.
Optional Field Toggle Mark every field as optional with one click — useful when generating types from a partial sample.
Type vs Interface Choose between interface declarations or type aliases to match your project conventions.
Browser-Only Production payloads with secrets, PII, or auth tokens stay in your tab. No upload, no logging.

Pro Tip

The generator can only see what's in your sample — fields that are null or omitted in the payload will be typed as null or skipped entirely. After generating, scan for null fields and broaden them (e.g. string | null) where the API spec says they're optional.

Walkthrough: Typing a REST Response

Capture a real response from your API in DevTools, paste it in, set the root type name to something like UserResponse, and click Generate. You'll get an export interface UserResponse at the top with named sub-interfaces for nested objects (Address, Friend, etc.). Drop the file into your types/ folder and import it from your fetch wrapper — instant end-to-end type safety.

Frequently Asked Questions

What happens with mixed-type arrays?

An array containing strings and numbers becomes (string | number)[]. Arrays of objects with different shapes get their fields merged into one interface with union types per field.

How are object keys with hyphens or spaces handled?

Non-identifier keys are emitted as quoted property names — 'kebab-key': string; — so the generated type compiles cleanly.

Can I regenerate types when the API changes?

Yes — just paste the new payload and click Generate. Use JSON Diff first if you want to see exactly which fields changed.

Does it generate validators or runtime guards?

No — only static TypeScript types. For runtime validation, pair the output with a library like Zod or io-ts using the same field shapes.