Numeric types validation not working correctly. #191
Replies: 1 comment
-
Thanks for reporting, this is a more or less known "issue". In C (and thus C++) float is distinguished from an integer. Your "error" comes from the underlying JSON-library we are using here which parses fractional numbers as floats. That in the JSON-schema standard they say that .0 is actually an integer is unfortunate, IMHO. Why do you put 75.0 on an integer field and not 75? What would you expect if there is 75.1 and the schema says it should be an integer. Why distinguish .0 and .1 ? I think it is highly incoherent to consider .0 as an integer. I don't see any practical use of it. But I'm looking forward to be convinced otherwise. If you have an idea of how to fix this in this library; please contribute. But handling the special case of .0 (of a float) is not really a thing for me. But why not if it is a trivial change. |
Beta Was this translation helpful? Give feedback.
-
file schema.json
file data.json
Expected results when validating data.json against schema.json: valid file.
Results I get: Invalid file ERROR: '"/weight"' - '75.0': unexpected instance type.
If I replace weight type by "number" the file is identified as valid and that is correct although type "integer" is also correct.
I should not get this error, based on JSON schema docs - https://json-schema.org/understanding-json-schema/reference/numeric.html.
If possible, I would appreciate a patch for this issue.
Beta Was this translation helpful? Give feedback.
All reactions