Generate TypeScript interfaces from JSON data
Infer TypeScript types from a JSON sample so you can type API responses without hand-writing interfaces.
- 1
When an API returns untyped JSON, you can infer the shape from a sample response. The generator examines keys, value types, and nesting to produce interfaces that match the observed structure.
- 2 JSON to TypeScript →
Paste a JSON sample (ideally a response with all fields populated). The tool outputs TypeScript interfaces with proper types for nested objects, arrays, and scalars.
- 3 json-format → json-to-ts
Use the chain to parse JSON, infer types, and emit formatted TypeScript with consistent naming (PascalCase interfaces, camelCase properties).
- 4
Review the output: optional fields (null or missing in the sample) should be marked with ?. Union types (a field that is sometimes string, sometimes number) need manual adjustment — the generator only sees one sample.
Frequently asked questions
- The generated types are too strict — some fields are optional in practice.
- The generator marks a field optional only if it is null or absent in the sample. If your sample happens to include the field, it will be required. Manually add ? to fields that may be absent in other responses.
- Should I trust inferred types for production?
- Inferred types are a starting point, not a contract. They reflect one sample, not the full API schema. For production, validate against the API's OpenAPI/JSON Schema spec, or use a runtime validator (zod, io-ts) to guard against shape changes.
Workflows that solve this
Learn more
Want to understand why?