What you get
{ "id": 42, "name": "Ada", "avatar": null,
"projects": [ { "id": 1, "title": "Engine" },
{ "id": 2, "title": "Notes", "archived": true } ] }export interface Root {
id: number;
name: string;
avatar: null;
projects: Project[];
}
export interface Project {
id: number;
title: string;
archived?: boolean;
}Each nested object becomes its own named type, based on its key (projects becomes Project). Keys that aren’t valid identifiers, like created-at, are quoted.
How the types are inferred
- Arrays of objects are merged: a key present in every item is required, one missing from some is optional.
- Mixed values become unions, like
string | number, andnullin some items givesstring | null. - A field that’s only ever null is typed
null. Paste a sample where it has a value to get the real type. - Empty arrays become
unknown[]. - Identical shapes are reused rather than duplicated.
Notes under the output tell you when any of these guesses were made, so you know which types to check by hand.
Broken JSON?
The input uses the same checker as the JSON formatter. Trailing commas, single quotes, unquoted keys, comments and missing brackets are marked where they are and fixed in one click, so you can paste straight from a JavaScript object or a log line.
Tips
- Paste a response with several items in its arrays to get accurate optional fields.
- Strings that hold dates are typed
string; JSON has no date type. - Turn on readonly for data you treat as immutable, like API responses.
- Rename the root type to match your endpoint, such as
UserResponse.
Need the same data in another format? Use JSON to YAML or JSON to CSV.
Questions people ask
How are optional fields detected?
?. The more examples you paste, the more accurate the types.Should I use interface or type?
What does the “| undefined” option do?
key?: T | undefined. You need this if your tsconfig has exactOptionalPropertyTypes turned on and you sometimes set those keys to undefined explicitly.