Skip to main content

[] is valid JSON. CSV still refuses it

Laravel prints []. TypeScript prints an empty Root. The PHP DTO is empty. CSV expects an array of objects.

Updated 2 min readMarkdown
[] is valid JSON. CSV still refuses it

[] parses. It is not the empty-box error, and it is not a trailing-comma failure. On the JSON converter the four formats still disagree. Conversion runs in the browser.

Laravel prints []. TypeScript prints an empty Root:

export interface Root {

}

The PHP class is still named DataTransferObject. It has declare(strict_types=1), no fields, and a constructor with an empty body. CSV rejects the paste with CSV conversion expects an array of objects. and clears that output.

Why CSV refuses a valid array

CSV from this converter expects an array of objects so it can build a header from top-level keys. An empty array has no objects and no keys. A scalar list such as [1,"a",true,null] is also rejected for CSV, while Laravel can still print a PHP list of those values. TypeScript prints export interface Root {} when the first item is not an object. The PHP DTO then prints a stub whose only body is the comment Provide a JSON object to generate properties.

Keep the cases separate

Paste Result
[] Valid JSON; CSV refuses
{"a":1,} Parse error; all outputs cleared
empty box Unexpected end of JSON input

Fix broken text in the JSON formatter. For CSV, use an array of objects.

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

No comments yet. Be the first to comment.