Menu

What a JSON converter drafts from the first object
📰

What a JSON converter drafts from the first object

DEV Community: laravel·Ameen Usman·10 days ago
#pYFHs9kq
#devtolaravel#devto#dev#meta#object
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.