Skip to content
OddsockLocal
Local
Source text
{
  "color": "red",
  "count": 2
}
1 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste a JSON sample into Source text.
  2. There are no options for the interface name. The root type is Root.
  3. Copy the interface or the type alias.
  4. Rename Root and split nested objects into named interfaces where the project expects that.

What is JSON to TypeScript?

A sample response is enough to sketch the type you will parse into, with the limits of a single example written in the output. JSON to TypeScript walks the value. An object becomes export interface Root with one field per key. Field names are quoted, which keeps keys that would be awkward as bare identifiers. Strings are string, numbers are number, booleans are boolean, and null is null.

Read more

An array becomes export type Root = Array<...>. If the items have different types, those types are joined with a vertical bar. One object cannot show that a field is optional. count is number here even when a JSON Schema call types the same 2 as integer, because this output is TypeScript and the value is a JSON number. Nested objects are inlined.

Use cases

  • A frontend engineer pastes an API sample and starts from interface Root instead of typing the fields.
  • A code review checks that Quantity became number and Item became string on a converted row.
  • An array of records is pasted so the type is an array of objects, matching CSV to JSON output.
  • A nested payload is turned into an inline object type before anyone splits it into named interfaces.
  • A fixture with null is pasted so the field is typed null, which flags a sample that never showed the real type.

Interface for color and count

{"color":"red","count":2}. For a row list, paste [{"Item":"Pen","Quantity":4}].

export interface Root { "color": string; "count": number; } The one-row array returns export type Root = Array<{ "Item": string; "Quantity": number; }>;

Why use Oddsock

The interface matches the sample you pasted, quoted keys included, so the gaps you still have to mark optional are visible.

Related tools

Using this tool

Quoted keys are legal for every JSON key, including keys with spaces or hyphens. You can remove the quotes when the key is already a safe identifier.