Tool
JSON samples to TypeScript and JSON Schema
Infer TypeScript interfaces, type aliases and JSON Schema from JSON samples. Review optional fields, unions, null and empty arrays, adjust field types, then copy or download consistent definitions locally.
1. JSON samples
Input stays in this tab: a local worker infers the structure, with no upload, URL fetching, storage or API calls.
Inferred from samples, not a complete API contract. Add varied real samples, review missing fields, null and empty arrays, then confirm the output with the API owner.
2. Inferred output
Primitive and array roots use a type alias even in interface mode; object structures become named interfaces. Schema properties remain open to additional fields.
Inference notes
Review field types and optionality
Paths use JSON Pointer escaping; /* means array elements. A type override replaces that entire field, including a nested object. Selecting “inferred” restores its inferred structure. Repeat-shape types are deduplicated again after every edit. Child field edits have no effect while their parent is overridden.
| Path | Inferred / current type | Override type | Optional |
|---|
Limits and interpretation
A field missing from some object samples becomes optional; explicit null stays null or forms a union. Empty arrays infer unknown[] until non-empty array samples provide evidence. Mixed values form unions; repeated object shapes share a named type. First-seen field order and two-space indentation are stable. Numbers infer number, never enums or date formats.
Limits: 500,000 characters, 20,000 JSON values, 500 inferred fields and 64 nesting levels. Duplicate keys and unsafe numeric integers are rejected with source positions to avoid silently losing evidence. This tool does not generate OpenAPI documents, fetch URLs, validate live backend responses or infer future fields from a single example.
FAQ
Is this a complete API contract?
No. Definitions are inferred only from the provided samples. Missing future fields, unseen union branches and business rules cannot be inferred. Add varied samples, inspect null and empty arrays, and review every inferred optional field.
How do I combine multiple response examples?
Choose the array-of-object-samples mode. It merges those objects into one contract and marks fields missing from some samples as optional. In single-value mode, an array remains an array root.
Do field edits change all output formats?
Yes. TypeScript interface, type aliases and JSON Schema share the same model. A field type override replaces the whole field; optionality changes the TypeScript question mark and Schema required list together.
Is input uploaded or fetched from a URL?
No. A local worker processes JSON in this tab. There is no upload, URL fetching, persistence or live backend validation. Schema allows additional fields; unknown[] and explicit null are shown rather than guessed.