JSON to TypeScript
Infer TypeScript types from JSON.
About this tool
Paste a JSON sample and get an exported TypeScript type with the right primitives, arrays and nested object types. The types come from the one sample you give it, so check optional and nullable fields yourself.
How to use
How it works
The tool walks the sample and maps each value: strings to string, integers and decimals to number, booleans to boolean, null to null, arrays to T[] with all items merged (differing fields become optional, differing types a union), and nested objects to inline object types. Every property is required because a sample cannot show which ones are optional.
Worked example
An API response
- Input
- {"id":1,"name":"Ada","price":9.5,"tags":["a"],"owner":{"email":"a@b.c"},"active":true,"note":null}
- Output
- export type tool = { id: number name: string price: number tags: string[] owner: { email: string } active: boolean note: null }
- Walkthrough
- note is typed null because the sample value is null; widen it to string | null if it can hold text.
Limitations
- Array items are merged: fields missing from some items become optional (?) and mixed item types become a union. Enums are not inferred.
- Nested objects are inlined rather than given their own named types.
- The root type is named tool.
Questions
How do I generate a TypeScript interface from JSON?
Does it create interface or type?
How does it handle null values?
Why is a field not optional?
Features
- Nested objects and arrays
- Integer and decimal to number
- Exported type alias
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
What Is A RESTful API?
Traversy Media
Most APIs exchange JSON—context for pretty-print and schema checks.
Watch on YouTubeSQL Tutorial - Full Database Course
freeCodeCamp.org
JSON often lands next to SQL exports when debugging data pipelines.
Watch on YouTube
- Getting started with JSON Schema
JSON Schema
When you outgrow ad-hoc validation and need a schema definition.
- Regular expressions
MDN
JS regex guide aligned with browser-based testers.