Support of numeric values over the 64-bit limits #138
Replies: 2 comments 2 replies
-
Strictly speaking, JSON Schema assumes that it is validating the document before it's decoded. For compatibility with JSON, maybe we can explain that since parsers can lose precision during the parsing, then it is legal to validate the parsed value if that value would be valid in the original document, even if the original value is not. We can think of this as an additional case in between "valid" and "invalid" — let's call it "coerced" (a value that was invalid in the original document, strictly speaking, but was able to be parsed into a valid value). There might also be a fourth class of values, let's call them "corrupted" (valid in the original document, but became invalid at parse time.) An example of a "corrupted" value: (I'm not sure how we address the "corrupted instance" case.) |
Beta Was this translation helpful? Give feedback.
-
Maybe I'm trying too hard to preserve the "validate what's written not what's decoded" assumption. Maybe we change this assumption entirely, to something like: "Validators should validate what the application actually sees instead of what is written in the document. For JSON parsers that use float64 math, validators should validate against this parsed value." with the condition:
This removes the possibility of a validator seeing NaN or Inf. |
Beta Was this translation helpful? Give feedback.
-
We have recently added several optional tests to the test suite that cover cases for very large and very precise numeric values (both floating point and integer). This was done citing that JSON supports arbitrarily large values.
While it's true that JSON supports these values, the specification does also contain this guidance:
We should take this advice into consideration when promoting these tests. I wonder if it's worth creating a new category of tests. "Optional" tests to me imply that the cases are typical, but the spec says support for them isn't strictly required. Big-num support seems more like an edge-case to me: something that could be supported if you really want, but it's a bit overambitious to do so.
Beta Was this translation helpful? Give feedback.
All reactions