I copied an API response into a blank file and started a TypeScript interface by hand. The payload was a list of two people. Each object had an id, a name, a role, and a meta object with an active flag. I typed the fields from the first person and assumed the second person used the same keys. The JSON converter at https://kepttools.com/json-converter makes that rule visible. Paste the text. It runs in the browser and drafts the interface from the first object only. The same paste can also become a PHP DTO, a Laravel array, or CSV. The sample below is the array the page fills, and the TypeScript is the converter's output for that text.
[ { "id" : 1 , "name" : "Ada" , "role" : "engineer" , "meta" : { "active" : true }}, { "id" : 2 , "name" : "Linus" , "role" : "founder" , "meta" : { "active" : false }} ]
Enter fullscreen mode
Exit fullscreen mode
TypeScript stops at Ada. Linus does not add a field. meta becomes its own interface because the value is an object.…