Skip to content

JSON to TypeScript

Paste a JSON sample and get TypeScript interfaces you can drop into your project. Nested objects become named types, arrays of objects are merged into one shape with optional properties, and you control naming and style.

Runs in your browserFreeNo sign-up

Processed on your device. Files and text stay in your browser and are not uploaded to our servers. How privacy works

How to use the JSON to TypeScript

  1. Paste a representative JSON sample, such as an API response.
  2. Set the root type name and choose between interface and type declarations.
  3. Decide whether keys missing from some array items should be optional, whether properties should be readonly, and whether to export.
  4. Copy the generated code or download it as types.ts.

Features

  • Named nested interfaces derived from key names (users → User, address → Address)
  • Arrays of objects merged into a single element type; inconsistent keys become optional
  • Union types for mixed values, including null
  • interface or type alias output, readonly and export options
  • Non-identifier keys are quoted; reserved names are suffixed automatically

How types are inferred

Each JSON value maps to a TypeScript type: strings, numbers and booleans to their primitives, null to null, and objects to a named interface. For arrays, every element's shape is inspected. Objects are merged so the element type has the union of all keys, and a key that isn't present in every element is marked optional (when that option is on). Mixed primitives become a union such as string | number.

The generator infers from the sample you give it, so a field that happens to be null in the sample will be typed as null. Provide a sample where fields have realistic values, or edit the output; the tool is a head start, not a schema.

Naming

Nested type names come from the key that holds them, converted to PascalCase and singularised for arrays: order_items becomes OrderItem. When two different keys produce the same name, a number is appended. Names that clash with built-ins such as Date or Map get a Type suffix.

Frequently asked questions

Can it generate types from a JSON Schema or OpenAPI spec?

No. This tool works from sample data. Schema-based generation is a different task and on the roadmap.

Why is a field typed as null?

The sample had null for that field, and null is all the generator can know. Use a sample with a real value, or change the type by hand.

How are numbers like 1 and 1.5 typed?

Both are number. TypeScript doesn't distinguish integers from floats.

Is my JSON uploaded?

No. Generation runs in your browser.

Other tools people use alongside JSON to TypeScript.

You might also like

Something useful from another corner of VoltKit.