JSON fails to parse with a trailing comment at the end of an array #15592

Open
opened 2026-01-31 04:42:58 +00:00 by claunia · 7 comments
Owner

Originally created by @elibarzilay on GitHub (Oct 20, 2021).

Windows Terminal version (or Windows build number)

1.10.2714.0

Other Software

No response

Steps to reproduce

In the settings file, put a comment at the end of an object with a comma after it.

This fails:

"actions": [
  {},
  // ...
],

Dropping either the , or the comment makes it work.

Expected Behavior

Should be parsed as usual since both terminating commas and comments are allowed, or forbid trailing commas (assuming that comments are a desired feature).

Actual Behavior

Settings could not be loaded from file. Check for syntax errors, including trailing commas.

Originally created by @elibarzilay on GitHub (Oct 20, 2021). ### Windows Terminal version (or Windows build number) 1.10.2714.0 ### Other Software _No response_ ### Steps to reproduce In the settings file, put a comment at the end of an object with a comma after it. This fails: "actions": [ {}, // ... ], Dropping either the `,` or the comment makes it work. ### Expected Behavior Should be parsed as usual since both terminating commas and comments are allowed, or forbid trailing commas (assuming that comments are a desired feature). ### Actual Behavior > Settings could not be loaded from file. Check for syntax errors, including trailing commas.
Author
Owner

@zadjii-msft commented on GitHub (Oct 20, 2021):

I suspect this is a jsoncpp bug. I know that they don't support a "trailing" comment, the comment has to be before some real value that it can attach the comment too. That being said, there's nothing open on their repo (or maybe I'm just bad at searching). We should probably drum up a minimal repro without the Terminal involved and post this upstream

@zadjii-msft commented on GitHub (Oct 20, 2021): I suspect this is a jsoncpp bug. I know that they don't support a "trailing" comment, the comment has to be before some real value that it can attach the comment too. That being said, there's [nothing open on their repo](https://github.com/open-source-parsers/jsoncpp/issues?q=is%3Aissue+trailing+comment+) (or maybe I'm just bad at searching). We should probably drum up a minimal repro without the Terminal involved and post this upstream
Author
Owner

@jamespack commented on GitHub (Jul 10, 2023):

I have a minimal repro example ready to go to file a bug at jsoncpp. But before I did, I did some searching and I cant find where trailing commas are permitted by the spec and most searches on StackOverflow indicate that they are not permitted.

https://stackoverflow.com/questions/201782/can-you-use-a-trailing-comma-in-a-json-object

From MDN:

image

Maybe a better error message could be produced?

@jamespack commented on GitHub (Jul 10, 2023): I have a minimal repro example ready to go to file a bug at jsoncpp. But before I did, I did some searching and I cant find where trailing commas are permitted by the spec and most searches on StackOverflow indicate that they are not permitted. https://stackoverflow.com/questions/201782/can-you-use-a-trailing-comma-in-a-json-object From MDN: <img width="649" alt="image" src="https://github.com/microsoft/terminal/assets/2086722/c445ca08-cc6a-4129-9669-e9241936bfd3"> Maybe a better error message could be produced?
Author
Owner

@jamespack commented on GitHub (Jul 10, 2023):

Still happy to open the issue if you think it'd be prudent :)

@jamespack commented on GitHub (Jul 10, 2023): Still happy to open the issue if you think it'd be prudent :)
Author
Owner

@lhecker commented on GitHub (Jul 10, 2023):

Many JSON parsers allow trailing commas as an extension to the spec, including jsoncpp with the allowTrailingCommas option. This is helpful, because trailing commas make editing and diffing JSON files easier.

@lhecker commented on GitHub (Jul 10, 2023): Many JSON parsers allow trailing commas as an extension to the spec, including jsoncpp with the `allowTrailingCommas` option. This is helpful, because trailing commas make editing and diffing JSON files easier.
Author
Owner

@jamespack commented on GitHub (Jul 10, 2023):

Right on. I will open an with them today then. Thanks for the clarification!

@jamespack commented on GitHub (Jul 10, 2023): Right on. I will open an with them today then. Thanks for the clarification!
Author
Owner

@jamespack commented on GitHub (Jul 10, 2023):

Here you go

https://github.com/open-source-parsers/jsoncpp/issues/1500

@jamespack commented on GitHub (Jul 10, 2023): Here you go https://github.com/open-source-parsers/jsoncpp/issues/1500
Author
Owner

@sba923 commented on GitHub (Sep 30, 2023):

Many JSON parsers allow trailing commas as an extension to the spec, including jsoncpp with the allowTrailingCommas option. This is helpful, because trailing commas make editing and diffing JSON files easier.

VScode doesn't like Windows Terminal's defaults.json:

image

@nguyen-dows does this deserve an issue?

@sba923 commented on GitHub (Sep 30, 2023): > Many JSON parsers allow trailing commas as an extension to the spec, including jsoncpp with the `allowTrailingCommas` option. This is helpful, because trailing commas make editing and diffing JSON files easier. VScode doesn't like Windows Terminal's `defaults.json`: ![image](https://github.com/microsoft/terminal/assets/12860484/89102bf7-4977-4c32-a7de-9117b22eed76) @nguyen-dows does this deserve an issue?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15592