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
Top comments (2)
In Go's encoding/json, a nil slice marshals to
nulland a nil map tonull. For machine-readable CLI output that distinction matters: a consumer checkingbranchescannot tell "nothing returned" from "empty list returned". We fixed this in agentdiet by always returning empty slices ([]string{}) instead of nil, so the JSON output is always an array.That distinction is the useful one. For a CLI consumer, null and [] are different contracts. If the caller is checking branches (or piping into jq), a nil slice that marshals to null reads like “no value,” while [] reads like “a list with zero items.”
Forcing empty slices so the JSON is always an array keeps that contract stable. On the converter side we hit a related split: [] is valid JSON and Laravel can print it, while CSV still refuses because it wants rows of objects, not an empty list. Same idea — the empty shape has to mean something predictable to whatever reads it next.