Utilo

JSON to TypeScript Converter – Free, Online, Private

Infer TypeScript interfaces from a JSON sample. Nested objects become named interfaces and arrays become typed lists.

Input
Output

How to convert JSON to TypeScript

  1. Paste a JSON value that looks like the payload you want to type.
  2. The page infers a type for every field, including nested objects.
  3. Copy the interfaces into your project and narrow anything that was only null in the sample.

What gets inferred

The converter walks the value. Objects become interfaces. The root object is named Root unless the payload itself is an array, in which case you still get a type alias plus any nested interfaces. Strings, booleans and finite numbers map to string, boolean and number. JavaScript cannot tell integers from floats, so every number is number. Null becomes a null union on that field. Arrays sample their elements. If every element is an object, the element type is one interface built by merging keys across the items. A key missing from some items is optional. An empty array has no evidence, so it becomes unknown[].

Names and collisions

Interface names come from the property name, converted to PascalCase. address becomes Address. A key that is not a valid identifier is quoted in the property and still produces a usable interface name. If two different objects would claim the same name, a numeric suffix is added. The property itself keeps the original JSON key, including camelCase or snake_case, because renaming fields would break the parse of a real response. This is structural typing, not a schema: a field that happens to be a string in this sample will not be a union with number until a sample shows a number.

Worked example

The sample user produces Root with id: number, name: string, active: boolean, tags: string[] and address: Address. Address has city and zip as strings. tags is a string array because both elements are strings. If one tag were a number, the element type would become string | number. There is no export settings panel on this focused page; interfaces are exported so you can paste them into a module. For Zod, Go, Rust, Java, C# or Python dataclasses, use the sibling converter. Those pages share the same inference ideas and emit that language's syntax.

Limits of sample-based types

A single payload cannot reveal optional fields that were simply present this time, or numeric strings, or dates stored as ISO strings. Those stay string. Discriminated unions are not invented from a type field; you get one interface with the keys you saw. If the API returns either an object or an error string, paste a representative array of both shapes when you can. The result is a starting point for a hand-written type, not a substitute for an OpenAPI document. Generation runs locally, so a response that contains a customer record can be typed without sending it to a typing service.

Frequently asked questions

Are the interfaces exported?

Yes. Each interface starts with export so the snippet can live in its own module.

How are optional fields detected?

Only by absence. If every object in an array has a key, the key is required, even if the API documents it as optional.

What about dates?

ISO date strings stay string. TypeScript has no JSON date literal. Brand them or parse them in your own code.

Can I convert JSON Schema instead?

This page reads an example value, not a schema. A schema has different keywords and would be a different tool.