[] is valid JSON. CSV still clears the output

2026-11-14来源 dev.toEnglish

I pasted [] into the JSON converter and expected one answer. The four formats disagreed. [] is valid JSON. It is not an empty text box, and it is not a parse error. Conversion stays in the browser. Nothing is uploaded.

What each format prints

Laravel walks the whole value and prints an empty PHP array:

[] 

TypeScript drafts from the first object when the root is an array. There is no first object, so the interface is empty Root with a blank line between the braces:

export interface Root { } 

The PHP DTO is still class DataTransferObject. It has declare(strict_types=1), no properties, and an empty constructor:

<?php declare(strict_types=1); class DataTransferObject { public function __construct(array $data = []) { } } 

CSV does not convert []. The error is CSV conversion expects an array of objects. and the output is cleared.

Not the same as a broken paste

A trailing comma such as {"a":1,} clears every format with Expected double-quoted property name in JSON at position 7 (line 1 column 8). A lone { stops at column 2. An empty box says Unexpected end of JSON input. Those are parse failures. [] parses. CSV is the format that still refuses it.

Repair broken JSON in the JSON formatter, then convert again. For CSV, paste an array of objects.

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

原文:https://www.a8q9.cn/en/article/is-valid-json-csv-still-clears-the-output-00c727.html

相关文章