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
{{ message }}
Repository navigation
Feature Request: Add Optional Support for Exotic NaN/Infinity Formats in JSON Parsing #2414
Support for Parsing Exotic NaN, Inf, and -Inf as an Optional Mode
The simdjson library currently adheres strictly to the JSON specification (RFC 8259), which does not allow special floating-point values like NaN, Inf, or -Inf.
However, many real-world datasets (e.g., from scientific computing, machine learning, or legacy systems) use these non-standard representations for special floating-point values.
Proposal
Add an optional parsing mode (e.g., via a flag or parser configuration) to allow parsing of the following exotic float literals:
json
Copy
Edit
{
"value1": NaN,
"value2": Inf,
"value3": -Inf
}
These would be interpreted internally as:
NaN → std::numeric_limits::quiet_NaN()
Inf → std::numeric_limits::infinity()
-Inf → -std::numeric_limits::infinity()
Implementation Ideas
This feature should be opt-in only to preserve spec-compliant behavior by default.
Interoperability with other JSON-like serializers that support exotic floats.
Now, in simdjson, we do have non-standard extensions, hidden behind macros that are disabled by default. They are user-contributed. Thus, if this feature is valuable to you, I invite you or someone you work with to prepare a pull request. We will give it full consideration.
Activity
lemire commentedon Aug 13, 2025
If I load you proposed JSON is JavaScript, I get...
If you load it in Python, you get:
I have written on the topic:
If your tool generates JSON that cannot be parsed by Python and JavaScript out of the box, please do not call it JSON.
The standard approach is to embed your special values in strings, as follows;
{"value1": "NaN","value2": "Inf","value3": "-Inf"}Now, in simdjson, we do have non-standard extensions, hidden behind macros that are disabled by default. They are user-contributed. Thus, if this feature is valuable to you, I invite you or someone you work with to prepare a pull request. We will give it full consideration.
lemire commentedon Aug 14, 2025
Note that the On-Demand API is already rich enough that you can provide your own parsing routines.
Nelson-numerical-software commentedon Aug 15, 2025
Thanks for your tips !!!
Work in progress (impressive) with exotic behavior implemented in nelson.
lemire commentedon Aug 15, 2025
@Nelson-numerical-software Wow.
Nelson-numerical-software commentedon Dec 10, 2025
fixed for me with tips #2540 is more revelant
Add support for parsing NaN and Infinity as requested in #1540, #2414,…