-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Strict/Relaxed JSON syntax #36
Comments
Hello. Are these check-boxes to vote? Cannot click them. |
No, these are not for vote. This is only a GitHub markdown syntax for checklist. |
I think it would be nice to bring into library as much functionality as possible till it reasonably affects speed/interface. |
From the parser point of view, the most tricky part seem to be the relaxed rules for Object keys (without quotes) and the For the other enhancements, I would vote for their adoption, e.g. via a (set of) parse flags. It may lead to binary bloat to handle all individual flag combinations from within
|
I think these relaxed syntax can be categorized in two groups: a grammar one, and a lexical one. For the grammar group, I think they can be implemented by overriding/augmenting the state transition table of strict syntax. For the lexical group, I think a more sophisticated tokenizer may be required. I am still not very clear about "Key without quotes". This may require extension on the parser as well as the tokenizer. |
It would also be very useful to represent fractions without its integer part, like .123 instead of 0.123, I have a 3D model with 2Mb, aprox 200Kb are zeros like that... |
Along the lines of busytypist's comment, from a user perspective these features are in two categories (that are basically the same as what busytypist says), things that add to what RapidJson can do within itself - ie extra information that can be encoded such as comments and inf/nan. The other category consists of things that make RapidJson more compatible with other generators (and human generators), such as extra commas and key quoting and stuff but which don't really add to the information in the stream. As a user who uses only one Json library for all purposes, this suggests that the first category is a little bit higher priority for me. |
my 2cents: comments (skipping them during parsing) and extra commas are most valuable for my usecases. |
Commands would be a neat feature! E.g { file: @filename } Would notice the @ as a load file command value and load and parse the filename. (I currently am using a string value with that sort of syntax and check it on parse, if it finds it it loads the new file if it isn't loaded yet with a circular include check mechanism.) |
I would rather suggest to go for some kind of extension mechanism, to handle syntax extensions (and maybe also parser relaxations). This could possibly be done by some set of parser policy classes, which can be customized by the user, e.g. by some traits parameter. |
Hi. Is this issue still active? I'd like to have support of comments because I use RapidJson to parse config files. |
If you just want to trim out the comments in JSON file before load into rapidjson, you can reference jsmin class used in the below open source project. https://code.google.com/p/page-speed/source/browse/lib/trunk/src/third_party/jsmin/cpp/?r=339 Then using MemoryStream to load the minified string and parse the stream with rapidjson::Document.ParseStream to do so. |
@M1chae1, I wouldn't like to use this method because:
|
@andrusha97 This issue is still active. I am now preparing for 1.0 release and these features will be added afterwards. If you would like to, you may implement your solution and I will adapt or take it as a reference. |
I would argue very much to keep Rapidjson as strict/standard compliant as possible by default. If a non-standard syntax should be supported, I think the user have to set some flags/options or whatever so that he/she actually have to make an effort to support the non-standard behaviour. I have seen way too many examples of applications supporting non-standard things just for the case of simplicity. It might be nice and convenient at the time of implementation, but in the long run it will nearly always lead to problems in one way or another. |
@erikfr I agree. |
Excuse my ignorance, but why wouldn't |
@kenrobbins Those can be implemented. It is a matter of fact that the standard does not support those. If we want to support that, it may need to set a spec for this. Different users/languages may uses different strings for those values. Also, some may need to handle negative infinity, some may not, for example. |
I'd like to add my vote for comments and trailing commas. Many thanks for rapidjson - seems to be a really great lib (I just started to use it today). |
I merged #443 for parsing single/multiple line comments, contributed by @andrusha97 . |
This adds kParseTrailingCommasFlag to allow a trailing comma at the end of maps and arrays. This is part of issue Tencent#36, adding optional support for relaxed JSON syntax.
Currently RapidJSON is tried to be as strict as possible to the JSON spec.
There are several requests in adding relaxed JSON syntax for parsing. Here lists some possible ones.
Root JSON type
Comment
Object
(A-Za-z\-_)+[0-9A-Za-z\-_]*
Array
String
Number
.
, e.g..123
0.
,123.
0xDEADBEEF
Infinity
andNaN
(Allow options for writing and parsing NaN/Infinity #641)These relaxed syntax may be useful for some applications. However, this may increase complexity of code base.
Would like to gather opinions on this.
The text was updated successfully, but these errors were encountered: