JSON Lark

Sheet 01 Type generator

JSON to TypeScript

Paste one JSON sample or several. JSON Lark draws up interfaces with optional keys, nullable fields and union types as you type, entirely in your browser.

JSON

TypeScript

export interface Root {
  id: number;
  login: string;
  createdAt: string; // ISO 8601 date-time
  plan: Plan;
  repos: Repo[];
}

export interface Plan {
  name: string;
  seats: number;
}

export interface Repo {
  name: string;
  stars: number;
  topics: string[];
  license: string | null;
  private?: boolean;
}

1 sample · 3 interfaces

General notes

How it works

Every sample is read as a value of the root type. JSON Lark merges what it sees: a key missing from some objects becomes optional, a value that is sometimes null becomes nullable, arrays holding different kinds of values become unions, and objects with the same keys and types share one interface. Paste more samples in new tabs, or several documents in one tab as JSON Lines or separated by a --- line.

The general notes

Declare as, nested objects
interface or type declarations, named for the key they came from (repos becomes Repo), or nested objects written inline.
Null values
Keep | null, treat null as a missing key, or both.
String-literal unions
Off by default. A string key with up to 8 distinct values, at least one of them repeated, becomes "active" | "invited".
Note ISO dates
Strings such as 2026-03-14T09:26:53Z stay string (that is what JSON.parse gives you) with a comment saying they hold dates.

More sheets in the set

The same inference for four more languages, plus tools for querying and changing JSON.

Questions

Is my JSON uploaded anywhere?

No. The types are generated by JavaScript running in this tab, and the page makes no requests with your data. The site counts page views with Cloudflare Web Analytics, which sets no cookies and never receives what you paste.

How does it decide which properties are optional?

A key becomes optional when some objects of that type do not have it, counting every item of an array and every sample you paste. Untick "Optional keys from all samples" to make every key required.

What happens with empty and mixed arrays?

An empty array gives unknown[] until another sample shows what it holds. Mixed arrays become unions such as (number | string)[]. Objects keyed only by numbers or UUIDs become Record<string, T> instead of an interface with numeric keys.

Why are numbers always number, never bigint?

Because JSON.parse returns numbers, the type matches what your code receives. Integers beyond 2^53 lose precision in JavaScript; if your API sends such IDs, ask for them as strings. The Go, Rust and C# pages pick 64-bit integer types for them.

My JSON has comments or trailing commas. Will it work?

The generator reads strict JSON and shows the line and column of the first problem. To fix single quotes, comments, trailing commas or missing brackets first, use JSONMender, a sister site that repairs broken JSON.