-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Ignore trailing comma in objects and arrays #1043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Issue #723 would include this if implemented. |
I had test the setting
After changing, However, when the number of the trailing commas is more than one, it still parses error. I think the above maybe not good enough.Feel free for a PR |
This seems like a useful feature. Just please be sure that a trailing comma fails for "strict mode". |
It seems to me like allowing a trailing comma in objects is quite straightforward: kimsey0@f0e7848 For arrays, an error is thrown in |
We need to determine what to do if both |
Also, I'm not completely sure about the distinction between |
@kimsey0 |
@dota17: It looks like the tests in |
@dota17: Looks good, but if we don't introduce support for trailing commas in the legacy |
Closing as fixed in #1098 |
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
I use the new Windows Terminal, which uses JsonCpp for parsing JSON configuration files, and currently requires those configuration files to be manually edited. It provides a file with defaults, from which I copy paste lines with settings for individual profiles (represented as JSON objects) into my user configuration file, then change the default values. However, those setting lines end with a comma, so if I paste them at the end of an existing profile object and forget to remove the comma, JsonCpp will fail to parse the configuration file and the Windows Terminal will pop up with a "Failed to reload settings" dialog.
More generally, this problem occurs for both objects and arrays when manually constructing JSON files or copy-pasting objects from ECMAScript code, which ignores trailing commas in object and array literals.
Describe the solution you'd like
I want JsonCpp, either by default or with a configuration setting, to ignore one trailing comma in objects and arrays while deserializing. I don't expect JsonCpp to keep any reference of this trailing comma or to be able to recreate it while serializing.
Describe alternatives you've considered
The main alternative I see is to keep the current behavior and to strictly enforce the correctness of parsed JSON. However, JsonCpp already supports comments, which is non-standard, so supporting trailing commas doesn't seem at odds with the direction of the project.
Between the alternatives of ignoring a trailing comma by default or by configuration, this depends on whether JsonCpp is allowed to break backwards compatibility by parsing files that would previously have resulted in an syntax error. I don't know the project stance on this.
JsonCpp could optionally support retaining and serializing trailing commas, but I don't see any value in that, except being able to more faithfully reproduce the source when deserializing and reserializing a file.
Additional context
This feature was also requested back in 2006 on Sourceforge. @cdunn2001 back then remarked:
The text was updated successfully, but these errors were encountered: