Logo JSON Parser Online

Generate TypeScript Interfaces from JSON

Paste a JSON object, set the root interface name (default: Root), optionally mark all fields as optional, and click Generate. The tool produces export interface declarations for the root object and every nested object it contains, ready to paste into a TypeScript project.

All JSON Tools

28 tools

Free, fast, runs in your browser. No login needed.

Made with ❤️ in India · © 2025 parsejsononline.com
INPUT
1
OUTPUT
1
✅ Ready
Characters: 0
Ctrl+Enter to run
What is this tool?

How to use

  1. Paste your JSON object into the INPUT pane.
  2. Set the root interface name in the text field (default: Root).
  3. Check Optional? if all fields across all interfaces should be marked with ?.
  4. Click Generate.
  5. Click Download to save the output as a .ts file.

How it works

The generator walks your JSON recursively. For each object it finds, it emits an export interface block. Primitive values map to their TypeScript equivalents: string, number, boolean. null values produce the null type.

Nested interface naming. Nested objects are named by concatenating the parent interface name and the key, separated by an underscore. A Root object with an address key produces a Root_address interface. This naming is functional but not idiomatic TypeScript — you'll likely want to rename these after generation.

Arrays. The generator uses the first element of a non-empty array to infer the item type. An array of objects produces InterfaceName[]. An empty array produces any[]. Mixed-type arrays are not handled — the generated type reflects only the first element.

Optional fields. Checking the Optional checkbox adds ? to every field in every generated interface. Useful when your JSON is a sample that may not include all possible keys in production.

Limits. null fields produce null rather than T | null — you'll want to adjust those manually if the field can hold other types. Date strings stay as string. There is no inference for union types (a field that holds either a string or a number in different records will show as whichever type the sample contains).

FAQ

Does it handle nested objects?

Yes. Every nested object gets its own interface declaration. The interfaces are output in order with the root interface first, followed by nested interfaces.

What happens with arrays?

Non-empty arrays use the first element to infer the item type. Empty arrays produce any[]. Arrays with mixed types (e.g., [1, "two", true]) are not supported — the type is inferred from the first element only.

What naming convention does it use for nested interfaces?

Nested interfaces are named ParentName_keyName — for example, Root_address for an address field under Root. This is functional but not idiomatic. Most TypeScript codebases would name this Address or IAddress. Rename after generating.

How do null values appear in the output?

Null fields are typed as null, not as T | null. If the field can hold other values in production, update the type manually after generating.

Can I make all fields optional?

Check the Optional? checkbox before clicking Generate. It adds ? to every field across all generated interfaces.

Does this use a TypeScript compiler or library?

No. The generator is a custom recursive function built into the tool. It does not invoke tsc or any TypeScript library. The output is a plain text .ts file.

Related tools

JSON to Python PydanticGenerate Pydantic BaseModel classes from JSON. JSON Schema GeneratorGenerate a JSON Schema definition from a sample. JSON FormatterFormat JSON before generating interfaces.