Paste JSON and get TypeScript interfaces or types: nested objects, optional fields, mixed arrays and nulls, with root name, export and readonly options.
When an API returns JSON and your code is TypeScript, you need types that describe it, and writing them by hand for a nested response is slow and error-prone. Paste a JSON sample here and get ready-to-use interface or type declarations: nested objects become their own named types, arrays are merged into a single element type, fields missing from some array items become optional, and null values become unions. It runs entirely in your browser, so API responses containing real data are never uploaded.
Every element of an array is merged into one type. If most objects have the keys id and name but only some have coupon, the generated type has coupon as an optional property (coupon?: string). If the same key holds different types in different items, the property becomes a union such as string | number. Arrays that mix primitives and objects become a parenthesised union array, for example (string | Item)[].
A null value becomes the type null, and when another item has a real value for the same key the result is a union such as string | null, with null always listed last. An empty array has no elements to learn from, so it is typed as unknown[]. Provide a sample with at least one element if you want a precise element type.
For plain JSON object shapes they are interchangeable in practice. Interfaces can be extended and merged with declaration merging and give slightly friendlier error messages; type aliases are required for unions and can express things interfaces cannot. This tool generates the same structure either way, so pick whichever your codebase uses.
No. Parsing and type generation both run in your browser with plain JavaScript, with no network request involved. That makes it safe to paste real API responses, though you should still avoid sharing secrets in code you commit.
Yes, because they are inferred from the one sample you provide. A field that happens to be a number in your sample may be a string in other responses, and a field that is always present in your sample may be optional in the API. Feed it a sample that covers the variations, or check the result against the API specification or a schema.
Keys such as "content-type" or "2fa" are quoted in the generated property list, and names for nested types are built from the key in PascalCase (an orders array produces an Order type). If two different shapes would get the same name, a number is appended, and identical shapes are reused under a single name.
JSON Tools formats and validates JSON, and the Data Format Converter changes the data between JSON, YAML, XML and other formats. This tool does neither: it reads the structure of your JSON and writes TypeScript declarations that describe it.
← All tools · Blog · Cheat sheets · FAQ