Menu

What a JSON converter drafts from the first object
📰

What a JSON converter drafts from the first object

DEV Community: laravel·Ameen Usman·11 days ago
#Y9ypbTeY
#devtolaravel#devto#dev#meta#name
Reading 0:00
15s threshold

I had an API payload in one window and a blank TypeScript file in the other. The payload was a list of people. Each object carried an id, a name, a role, and a meta object with an active flag. I was ready to type the interface by hand and assume the second person would have the same keys as the first. That assumption is the useful part to check. The JSON converter at https://kepttools.com/json-converter reads the paste in the browser and drafts the interface from the first object only. The same text can also become a Laravel array, a PHP DTO, or CSV. The blocks below are that sample, run through the converter, not a tidied rewrite of it.

The Sample button uses this array:

[ { "id" : 1 , "name" : "Ada" , "role" : "engineer" , "meta" : { "active" : true }}, { "id" : 2 , "name" : "Linus" , "role" : "founder" , "meta" : { "active" : false }} ]

Enter fullscreen mode

Exit fullscreen mode

Laravel keeps both people, and it keeps meta nested as a PHP array:

[ [ 'id' => 1 , 'name' => 'Ada' , 'role' => 'engineer'…

Continue reading — create a free account

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