JSON to TypeScript Interface
A sample JSON response is enough to write a matching TypeScript interface. Pretty-print your sample in the tool below, then follow the type-mapping rules to write the interface by hand.
Type by inference
Read the JSON value and pick the TypeScript type: a number becomes number, a string string, true/false becomes boolean. So "id": 42 maps to id: number.
Arrays and nested objects
An array of strings is string[]; an array of objects gets its own interface used as Thing[]. A nested object becomes a separate interface, referenced by name, so each level stays readable.
Null and missing fields
A JSON null means the type should include | null. A field that is sometimes absent should be marked optional with ?. Since one sample cannot reveal every optional field, widen the interface once you have seen more responses.
FAQ
Can one sample produce a complete interface?
It produces a starting point. A single sample cannot show optional or nullable fields that happen to be present, so review the interface against more responses.
How do I type an empty array?
An empty array gives no element type. Default to unknown[] or any[] and tighten it once you see a populated example.
Should I use interface or type?
Either works. interface is common for object shapes and supports declaration merging; type is fine and needed for unions.