Convert JSON to TypeScript Interfaces
Paste one JSON document and get an export interface for every object in it. Keys missing from some siblings become optional, arrays of objects become an interface for the element type, and values that disagree become a union.
- Optional keys come from absence. A field present in every sampled object stays required; one missing from any sibling gets
?. That is the only inference JSON supports, so give it an array of several real records rather than one. - It cannot see a field that never appears. A key every element omits is absent from the interface, not optional. Two documents with different shapes produce two interfaces, not one wider one.
- Nothing here is validated against your code. String-literal unions, branded IDs and
Datefields are judgements only you can make. This gives you the shape your sample implies; you edit it.
Frequently Asked Questions
Is my JSON private?
Yes. Parsing and validation happen in your browser. Your payload is never transmitted to a server, so it is safe to paste data you would not upload elsewhere.
Why does it say my JSON is invalid when another tool accepts it?
Most other tools are lenient. Strict JSON forbids trailing commas, comments, single quotes, unquoted keys, and NaN. JSONBeautify follows the spec, so it reports the exact position of the first violation instead of silently coercing your input.
Does minifying JSON break anything?
No, for valid JSON. Whitespace outside string literals is insignificant, so removing it is safe. Keep key order in mind if a consumer depends on it, since beautifying and re-minifying preserves order but reformatting tools are free to differ.