convert --to=ts --indent=2type a query, e.g. $.users[0].name
IDLE
stdin
1
stdout
Paste a sample API response and get TypeScript interfaces that describe it. The types are inferred from every item in your arrays, and everything runs in your browser.
How the types are inferred
Every object gets an interface named after the key that holds it, so a users array gives you a User interface. All items of an array are read together: a key that appears in some items but not others becomes optional (?), and a key whose values differ in type becomes a union such as string | null.
Objects with exactly the same shape share one interface instead of producing copies. Keys that are not valid identifiers are quoted, numbers are typed as number, and an empty array becomes unknown[] because there is nothing to infer from.
Getting good results
The interfaces are only as complete as the sample. Paste a response that includes the optional fields and null cases you care about, or several items in an array, and the types will cover them.
Use a query to generate types for one part of a document, choose 2 or 4 spaces of indentation, then copy the result or save it as a .d.ts file.
Questions
Does it write type or interface?
Objects become exported interfaces. When the top level is not an object, for example a plain array, the result is an exported type called Root.
Can it tell integers from decimals?
TypeScript has one number type, so both become number. The JSON Schema generator on this site does keep that difference.
Can it generate Zod or other schemas?
Not on this page. It writes TypeScript interfaces only.
Is my JSON sent anywhere?
No. The interfaces are generated in this page from the data you paste.