[1,"a",true,null] drafts an empty Root
Laravel keeps the list. TypeScript and the PHP DTO need a first object. CSV expects an array of objects.
![[1,"a",true,null] drafts an empty Root](https://cdn.hashnode.com/uploads/covers/6acdedf030c1cb3b7081ed53/a2aab95f-313a-4457-909c-6eed6348894c.png)
[1,"a",true,null] parses. On the JSON converter it still does not produce a useful TypeScript or PHP schema. Conversion runs in the browser.
Laravel prints a PHP list of the four values. TypeScript prints an empty interface because the first item is a number:
export interface Root {}
The PHP DTO is a stub. Its only body is the comment Provide a JSON object to generate properties. CSV clears the output with CSV conversion expects an array of objects.
Object drafts need an object
When the root is an array, TypeScript and the PHP DTO read the first object. A scalar list has no first object. That is the same reason [] leaves TypeScript and the PHP class empty, and why CSV refuses both pastes. Laravel can still print [] or a list of scalars because it walks the whole value.
For property values on a real object, a whole number such as 1 is int on the PHP DTO, 1.5 is float, and TypeScript types both as number.
Keep parse errors separate
{"a":1,} is not this case. That trailing comma produces Expected double-quoted property name in JSON at position 7 (line 1 column 8) and empties every output. Repair it in the JSON formatter, then convert again. For TypeScript, PHP DTO, or CSV, paste an object or an array of objects.
Guide: https://kepttools.com/guides/json-to-typescript-php-dto-laravel
Comments
Join the discussionNo comments yet. Be the first to comment.




