Developer Runs in your browser 100% Private

JSON Formatter & Type Generator

Paste JSON to format, validate and inspect it, then generate TypeScript interfaces, Go structs, Python dataclasses or a JSON Schema from the same payload. Parse errors report an exact line and column. Parsing and type inference both run locally, so production payloads never leave your machine.

Price:
Free, no sign-up
Data:
Processed locally
Reviewed:

Interactive json formatter

Input

Input Data

391 B · 11 lines

Valid JSON

Output

Results & Output
Keys
19
Nodes
22
Max depth
4
Arrays
1
Quick Answer

How do I convert JSON to a TypeScript interface?

Paste the JSON and switch to the Types tab. Each object becomes an interface, keys present in only some records are marked optional, mixed primitives become a union, and fields that are sometimes null are typed as nullable. Feed it the widest realistic sample you have rather than a single record, because inference can only describe what it sees.

How to use the json formatter

  1. Paste your JSON: Drop in a payload, or load the sample to try it.
  2. Format or minify: Beautify with your chosen indentation, or minify for transport.
  3. Generate types: Switch to the Types tab for TypeScript, Go, Python or JSON Schema.
  4. Copy the result: One click copies the output, ready to paste into your codebase.
Technical Architecture & Logic

How the json formatter works

Type inference from a sample

Generating a type from data is an inductive guess: the payload shows you one sample of a structure, and the type must describe every sample. The inference pass here builds a small type lattice — null, boolean, number, string, array<T>, object{k:T} — and unifies types pairwise as it walks the tree.

The unification rules

  • Two objects unify into one object; keys missing from either side become optional.
  • An array's element type is the unification of every element it contains.
  • null unified with T yields nullable T, not a union with null as a separate case.
  • Incompatible primitives produce a union, preserved in the order first seen.

Why the sample matters

Inference can only describe what it sees. A field that is always a string in your sample but occasionally null in production will produce a type that lies. Feed the generator the widest realistic payload you have — ideally a captured page of API results rather than a single record — and treat the output as a strong first draft to review, not a contract.

Naming

Nested objects are named from their key, singularised when the key is plural and converted to PascalCase, so {"orderItems": [...]} yields an OrderItem interface. Collisions get a numeric suffix rather than silently merging unrelated shapes.

JSON Formatter — frequently asked questions

No. Parsing, formatting and type generation all happen in your browser with the native JSON parser and a local inference pass. Nothing is transmitted, which is what makes this safe for payloads containing production data.

When the same key appears in some objects of an array but not others, it is marked optional — field?: T in TypeScript, a pointer in Go, Optional[T] in Python. Keys whose value is sometimes null get a nullable type instead.

Types are unified across all elements. Compatible objects merge into one interface with optional keys; genuinely different primitives produce a union such as string | number, and an empty array becomes unknown[].

Several megabytes comfortably. The editor virtualises long documents and type inference is a single pass, so the practical ceiling is your available memory rather than a hard limit.

Important Disclaimer

Parsing, validation, and type inference run strictly client-side within your browser. Inferred interfaces reflect the structure of the provided data sample; always audit generated types and schemas before incorporating them into mission-critical systems.

Published , last reviewed . The formulas and assumptions behind this tool are verified for mathematical accuracy.