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 Data391 B · 11 lines
Output
Results & OutputHow 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
- Paste your JSON: Drop in a payload, or load the sample to try it.
- Format or minify: Beautify with your chosen indentation, or minify for transport.
- Generate types: Switch to the Types tab for TypeScript, Go, Python or JSON Schema.
- Copy the result: One click copies the output, ready to paste into your codebase.
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.
nullunified withTyields nullableT, 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.
Official resources & government references
Verified references, primary standards specifications, and official publications governing the rules and calculations implemented in this tool:
RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
The definitive normative technical specification for JSON syntax, grammar, and encoding standards.
ECMA-404: The JSON Data Interchange Standard
The official international open standard defining JSON object structures and literal types.
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.