DEV Community

Cover image for A trailing comma clears the converter output
Ameen Usman
Ameen Usman

Posted on

A trailing comma clears the converter output

I pasted {"a":1,} into the JSON converter. The output box went empty. The message was Expected double-quoted property name in JSON at position 7 (line 1 column 8). Position 7 is the } after the comma, and column 8 is that same spot counted from 1. A bad paste is not kept in part. Nothing from the previous conversion stays on the page.

Two other pastes that clear the box

A lone { produces Expected property name or '}' in JSON at position 1 (line 1 column 2). An empty box produces Unexpected end of JSON input. Each of these three inputs leaves the output empty. The page shows that parse error and does not send the paste to an API.

An empty array is valid JSON

[] parses. It is a different result from an empty text box. Laravel prints []. TypeScript prints an empty Root with a blank line between the braces.

export interface Root {

}
Enter fullscreen mode Exit fullscreen mode

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

<?php

declare(strict_types=1);

class DataTransferObject
{


    public function __construct(array $data = [])
    {

    }
}
Enter fullscreen mode Exit fullscreen mode

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

One tip

JSON does not allow a comma after the last value. Repair the text in the JSON formatter, then convert again.

The rest of the limits are in the guide: https://kepttools.com/guides/json-to-typescript-php-dto-laravel

Top comments (0)