Skip to content
JSON Runs offline

JSON to TypeScript

Turn one JSON example into readable, multi-interface TypeScript types.

Input

0 chars

Output

0 chars
Ctrl

Questions

Why does a nullable field just become `null` instead of `string | null`?

This tool infers types from one example document, not a schema. If a field is null in your sample, there is no other value in that document to widen it against, so it comes out as the literal type null - widen it by hand to `string | null` (or whatever the real type is) if you know the field can hold other values.

What happens with an empty array, like "tags": []?

There are no elements to infer a type from, so it becomes `unknown[]`. This is a documented limitation, not a bug - supply an example with at least one element in the array if you want a real element type.

How are interface names chosen, and can two fields collide?

Each nested object is named from its field name using a light PascalCase-and-singularize heuristic (e.g. "orders" -> Order), not a grammar engine, so unusual plurals may not singularize perfectly. If two different fields would produce the same name for genuinely different shapes, the tool appends a number (Order, Order2, ...) rather than overwriting one; identical shapes at different field names are left as separate interfaces without deduplication, by design.

What happens when the same field holds objects with different keys across an array?

They are merged into one interface: the field list is the union of every key seen, and any key that is not present in every element is marked optional (regardless of the general "make everything optional" toggle, which is a separate, blanket setting).

Open JSON to PHP Array

JSON to PHP Array

Convert JSON into a paste-ready PHP array literal, with short or long syntax and a variable or define() wrapper.

JSON
Open JSON Formatter

JSON Formatter

Format, indent and inspect JSON with clear error reporting.

JSON
Open JSON Validator

JSON Validator

Check whether JSON is valid and see exactly where it breaks.

JSON