How to use
- Paste a JSON sample into the input. A single API response works, and so does an array holding several of them.
- Choose TS interface, TS type, Zod or JSON Schema. All four are rendered from the same analysis.
- Adjust the root name, how
nullis handled,export,readonlyand date detection. - Copy the result or save it as a
.tsfile (.jsonfor JSON Schema).
Inference rules
| Input | Result |
|---|---|
| Object | A named interface. The root uses the root name; nested ones use the key in PascalCase (shipping_address becomes ShippingAddress) |
| Array of objects | All elements are merged into one type. A key missing from some elements becomes optional (?) |
| Array item name | The key made singular (users becomes User, categories becomes Category, addresses becomes Address). The rule is simple, so news becomes New | rename it if needed |
| Same key, different types | A union (number | string) |
| Objects with the same shape | One shared type, whatever the key order. A name clash gets a number, as in Item2 |
| Empty array | unknown[] |
| Mixed array | (string | number)[] |
null |
A union by default (string | null), or just null when every value is null. You can switch to an optional key or unknown |
| Key that is not an identifier | Quoted ("first-name": string) |
| Date string | A // ISO date comment for standard formats (z.string().datetime() in Zod) |
The formats treated as dates are date-times with a zone, such as 2026-10-07T12:00:00Z or +09:00, and date-only strings such as 2026-10-07. A date-time without a zone would be rejected by datetime(), so it stays a plain string.
Example
For {"users":[{"id":1,"email":"a@x.com"},{"id":2,"phone":null}]}, phone appears only in the second element and email only in the first, so both become optional.
export interface Root {
users: User[];
}
export interface User {
id: number;
email?: string;
phone?: null;
}
Converting {"id":7,"name":"Kim","createdAt":"2026-10-07T12:00:00Z","tags":[]} to Zod with .int() turned on gives:
export const RootSchema = z.object({
id: z.number().int(),
name: z.string(),
createdAt: z.string().datetime(),
tags: z.array(z.unknown()),
});
Things to know
- A small sample cannot reveal optional keys. With one response, every key in it looks required. Put several responses in one array and the missing keys and
nullvalues show up. - Empty arrays and values that are only
nullhave no known type. They come out asunknown[]andnull, so fill in the real type yourself. - Numbers are not split into integer and float. TypeScript says
number; only in Zod can.int()be added, and only when every sampled value is an integer. - interface vs type: for plain object shapes they are nearly the same. An interface can be extended later under the same name, while a type shares syntax with unions and tuples.
- Why Zod: TypeScript types exist only at compile time, so they cannot stop a server response from changing shape. Calling
parseon a Zod schema checks the shape at runtime, andz.infergives you the same type. - JSON Schema output follows draft 2020-12. Optional keys are left out of
required, and nested objects go into$defs. - Input is limited to 2 MB and 64 levels of nesting.
Related tools
To check syntax first, use the JSON Formatter. To change format, try JSON to YAML or JSON to CSV. To see how two responses differ, use JSON Diff.
The JSON you enter is processed in your browser only and is never sent to a server.