You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
A portion of geometric JSON data contains NaN/Infinity as double values, which currently simdjson fails to parse.
Describe the solution you'd like
Support parsing NaN/Infinity as double value, a subset of relaxed JSON syntax. If performance will be affected, the feature may live under some option.
Describe alternatives you've considered
I cannot think of any alternatives.
❯ node
Welcome to Node.js v15.12.0.
Type ".help" for more information.
> JSON.parse("{\"x\":1}")
{ x: 1 }
> JSON.parse("{\"x\":inf}")
Uncaught SyntaxError: Unexpected token i in JSON at position 5
> JSON.parse("{\"x\":infinity}")
Uncaught SyntaxError: Unexpected token i in JSON at position 5
@amosbird Are you willing to implement and test support for the format that you describe knowing that it is not valid JSON and does not follow the specification?
There is a larger conversation which is not part of simdjson as a library as to whether json should have supported the full IEEE 754 floating point spec, which does in fact have -inf, +inf and NaN's as valid floating point values.
So my +1 on a request to one day maybe support the option, but I understand that it is a wish list item.
amosbird Are you willing to implement and test support for the format that you describe knowing that it is not valid JSON and does not follow the specification?
I'm not sure whether that was a rhetorical question, but I would be willing to dedicate time if you can recommend an architectural way to achieve it. Would it be in the form of a configurable token for the parser object? Clearly, this is not a spec driven token, so it is by definition application defined. The above values are what python happens to use. It could alternatively be in the form of a "dialect" enumeration.
I think we're on board for non standard features, as long as they are somewhat common and can be turned off. Trailing commas and comments come to mind as valuable and reasonably common additions to the spec.
I would be ready to tackle this sometime in the new year. What is the desired architectural approach here? Templated mixin? Dialect enum passed to constructor?
The RFC does not permit the representation of infinite or NaN number values. Despite that, by default, this module accepts and outputs Infinity, -Infinity, and NaN as if they were valid JSON number literal values
It is important to understand that this implies that the output can often not be read by other parsers. So it is an interoperability issue.
Thanks @lemire: I think the 4 ground rules you set out could be "fairly easily" achievable given the very limited scope of the feature. I will have some spare cycles in the near future and will make an attempt.
It does involve adding new atom types to JSON. JSON recognizes null, true, false, numbers, strings. One needs to add entirely new atoms. It is not trivial. E.g., it is not a few hours of work. This requires probably a few days, I would estimate, if one must adds tests and so forth.
I just want to comment - there is continued interest in this feature! We were hoping to switch to simdjson, but lack of support for NaN ended up being a showstopper.
Having a macro that enabled support would be amazing
@codeinred As a general rule, we follow the specification. The JSON RFC states:
Numeric values that cannot be represented in the grammar below (such as Infinity and NaN) are not permitted.
If you (or a colleague) want to implement this feature as an optional (disabled by default) feature, then it is likely we will accept it if it is well done.
But it is not and it is not going to be on our roadmap. Unless, of course, the JSON RFC changes.
To put it another way, if you need non-standard features, you need to bear the cost of these non-standard features.
Activity
lemire commentedon Apr 7, 2021
For people reading this, we follow RFC 8259, see https://tools.ietf.org/html/rfc8259
It states:
Here is the result in Python...
Result in JavaScript:
@amosbird Are you willing to implement and test support for the format that you describe knowing that it is not valid JSON and does not follow the specification?
amosbird commentedon Apr 7, 2021
Thanks for the detailed explanation. I agree we should stick with the specification.
lemire commentedon Apr 7, 2021
@amosbird Thanks for your comments.
memetb commentedon Dec 26, 2021
Just a minor point on the above conversation that python's
jsondoes in fact support infinity, even though json's RFC is blind to it.There is a larger conversation which is not part of simdjson as a library as to whether json should have supported the full IEEE 754 floating point spec, which does in fact have -inf, +inf and NaN's as valid floating point values.
So my +1 on a request to one day maybe support the option, but I understand that it is a wish list item.
@lemire: to answer your request here:
I'm not sure whether that was a rhetorical question, but I would be willing to dedicate time if you can recommend an architectural way to achieve it. Would it be in the form of a configurable token for the parser object? Clearly, this is not a spec driven token, so it is by definition application defined. The above values are what python happens to use. It could alternatively be in the form of a "dialect" enumeration.
jkeiser commentedon Dec 27, 2021
I think we're on board for non standard features, as long as they are somewhat common and can be turned off. Trailing commas and comments come to mind as valuable and reasonably common additions to the spec.
memetb commentedon Dec 30, 2021
I would be ready to tackle this sometime in the new year. What is the desired architectural approach here? Templated mixin? Dialect enum passed to constructor?
lemire commentedon Dec 30, 2021
Python is a particular case, its behaviour is documented as non-standard compliant:
It is important to understand that this implies that the output can often not be read by other parsers. So it is an interoperability issue.
JavaScript:
In Go:
It fails.
How this could be used in simdjson is somewhat secondary, but some ground rules can be set:
memetb commentedon Dec 30, 2021
Thanks @lemire: I think the 4 ground rules you set out could be "fairly easily" achievable given the very limited scope of the feature. I will have some spare cycles in the near future and will make an attempt.
lemire commentedon Dec 30, 2021
It does involve adding new atom types to JSON. JSON recognizes null, true, false, numbers, strings. One needs to add entirely new atoms. It is not trivial. E.g., it is not a few hours of work. This requires probably a few days, I would estimate, if one must adds tests and so forth.
codeinred commentedon Feb 15, 2024
I just want to comment - there is continued interest in this feature! We were hoping to switch to simdjson, but lack of support for NaN ended up being a showstopper.
Having a macro that enabled support would be amazing
codeinred commentedon Feb 15, 2024
Since this issue was closed, could I open a new one requesting optional support behind a feature flag?
lemire commentedon Feb 15, 2024
@codeinred As a general rule, we follow the specification. The JSON RFC states:
If you (or a colleague) want to implement this feature as an optional (disabled by default) feature, then it is likely we will accept it if it is well done.
But it is not and it is not going to be on our roadmap. Unless, of course, the JSON RFC changes.
To put it another way, if you need non-standard features, you need to bear the cost of these non-standard features.
I am marking this issue as resolved.