-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Precision and Scale for Decimal Values #8
Comments
This sounds like a niche usecase to me. To accommodate these kind of use cases |
I could see that for the scale case, but what about precision? Precision seems to be a fairly standard use-case for schemas... |
@chapmanjw Is this related to json-schema-org/json-schema-spec#152? |
Updated the post, had meant to show an example where min scale is 2 and max scale is 4, thus 1.11, 1.111, and 1.1111. And in this example, 1.1 would not be valid. |
@chapmanjw Can you elaborate more on why |
@awwright I am working on taking certain existing schemas defined in Ion and converting them to JSON Schema to enable use of these schemas in JSON-based REST APIs. To the degree possible, I am looking for JSON Schema equivalents of the features supported by the Ion-based schema. For scale, that schema supports min / max constrains (similar to to the scale range in Ion Schema - Scale).
If there remains no equivalency for minScale in JSON Schema, that constraint would likely get dropped altogether during conversion. And internally handle padding 0s to the decimal values when necessary to pass the validation of the Ion-based schema. |
@awwright The use-case for precision in this schema conversion is exactly the same as the range of precision defined in Ion Schema Precision. It is the minimum or maximum total number of digits in the numeric value. There isn't any scientific notation concern for this use-case. The common instances in the Ion-based schemas that I am converting use precision as a method of indicating the min/max length of the number as if it were a string. As with the scale case, I am looking to ensure each of these features of the Ion-based schema are covered so that any future use does not break the conversion or result in invalid payloads due to improperly describing the requirements. Until a JSON Schema equivalency of precision exists, these properties would likely need to be expressed as strings with a format or with a regex pattern. |
I'm taking a little bit to read up on Ion, this is the first I've heard of it. Off-hand and personally, it doesn't seem to me this is a property worth porting or converting between. The vast majority of JSON Schema validators would not be able to validate a property like this. Which is not much of a problem, they would just have to throw an error if it's used in a schema. I imagine usage of such a keyword wouldn't see much adoption if this was the case. |
@awwright For precision, scale, or both? |
Gentlemen - we contemplate the tip of an iceberg: JSON Schema does not yet support assertions, constraints in the form of expressions. I suggest to look at the problem at hand before the background of the following paragraph from the specification of SHACL, the new validation language for RDF "Part 1 of this specification introduced features that are built into the Core of SHACL. The goal of this Core is to provide a high-level vocabulary for common use cases to describe shapes. However, SHACL also provides mechanisms to go beyond the Core vocabulary and represent constraints with greater flexibility. These mechanisms, called SHACL-SPARQL, are described in the following sections. " https://www.w3.org/TR/shacl/#sparql-constraints
I am going to open an issue addressing this very general question. |
I'm with @johandorland . This sort of relative niche case (totally valid but not incredibly common) is exactly why we added support for modular vocabularies. @chapmanjw as more implementations of draft 2019-09 or later become available, I'd suggest that you create a vocabulary to address Ion-specific issues, or perhaps just floating point issues. @awwright @Relequestual do either of you see this as likely to be added to the Validation spec? We need a process for deciding when to close requests on the grounds that they should be handled by 3rd-party vocabularies. |
...although I do agree that there's a stronger case for a While float/decimal issues are common in some areas of programming, they haven't come up all that often with JSON Schema. And when they have, they tend to be around string-based solutions anyway. |
I'm still having trouble figuring out what minScale is supposed to do. Why should I'd like to see an "in the wild" use case (some sort of testimony that this solves a real-world problem), and implementation that solves that problem. |
While I understand that this can be solved by using string-based solutions as has been said, if you want a use case, forcing a minScale has a solution regarding significant figures. The value |
Regarding use cases, consider a location expressed as decimal latitude and longitude, e.g. from a GPS source. The scale of each value corresponds to the precision of the location. The co-ordinates At the other extreme, However, I agree that there would be a challenge implementing this in practice: although JSON itself defines "numbers" in terms of their decimal representation, common practice is to decode them as a language-native type, usually floating point, before applying any validation. That means that most implementations simply can't tell the difference between This already makes That suggests this is yet another case that should be folded into #45: the scale and precision options would realistically be used when embedding numeric values in a JSON string. |
For decimal values, I have a use-case with minimum and maximum constraints on precision and/or scale. Is there an existing way to express maximum/minimum precision and scale?
I am familiar with multipleOf where a specific scale can be defined, for example:
{ "multipleOf":0.01 }
For my particular use-case, this only works when the min/max scale is the same (i.e. 2 in this case).
However, I don't see a way to express these constrains when the min/max scale values are different, such as a min scale of 2 and a max scale of 4 (where 1.11, 1.111, and 1.1111 are all valid values).
Additionally, I don't see a way to express precision.
Is there a way to accomplish min/max scale and precision given currently supported syntax?
If not, could these constraints be consider for a future draft?
The text was updated successfully, but these errors were encountered: