[1,"a",true,null] drafts an empty Root

I pasted [1,"a",true,null] into the JSON converter. It is valid JSON. The four formats still disagreed. Parsing stays in the browser. Nothing is uploaded. What each format does Laravel walks the whole value and prints a PHP list of those four values: 1, "a", true, and null. TypeScript drafts from the first object when the root is an array. The first item is a number, not an object, so the interface is empty: export interface Root {} The PHP DTO prints a stub class. The only body is the comment Provide a JSON object to generate properties. There are no typed properties for the scalars. CSV rejects the paste. The error is CSV conversion expects an array of objects. and the output is cleared. Why the first item matters TypeScript and the PHP DTO are object drafts. A list of scalars has no first object to read keys from. Laravel does not need that shape, so it still prints the list. CSV needs top-level object keys for a header, so it refuses both this pas

[1,"a",true,null] drafts an empty Root

I pasted [1,"a",true,null] into the JSON converter. It is valid JSON. The four formats still disagreed. Parsing stays in the browser. Nothing is uploaded.

What each format does

Laravel walks the whole value and prints a PHP list of those four values: 1, "a", true, and null.

TypeScript drafts from the first object when the root is an array. The first item is a number, not an object, so the interface is empty:

export interface Root {}

The PHP DTO prints a stub class. The only body is the comment Provide a JSON object to generate properties. There are no typed properties for the scalars.

CSV rejects the paste. The error is CSV conversion expects an array of objects. and the output is cleared.

Why the first item matters

TypeScript and the PHP DTO are object drafts. A list of scalars has no first object to read keys from. Laravel does not need that shape, so it still prints the list. CSV needs top-level object keys for a header, so it refuses both this paste and [].

A whole number such as 1 is int on the PHP DTO when it is a property value. 1.5 is float. TypeScript types both as number. That path only appears when the paste is an object (or an array of objects) with those fields.

Related refusals

[] is also valid JSON. Laravel prints []. TypeScript prints an empty Root with a blank line between the braces. The PHP class is empty DataTransferObject. CSV again says it expects an array of objects.

A trailing comma such as {"a":1,} is different. That is a parse error and clears every format.

Guide: https://kepttools.com/guides/json-to-typescript-php-dto-laravel

Share