Ordering of Arrays and Strings #91
Replies: 3 comments 6 replies
-
I think after witnessing the mess that Javascript has with implicit type conversion, we should add a to_number() function that accepts strings and numbers, and returns a number. Erroring if no number can be derived. |
Beta Was this translation helpful? Give feedback.
-
Note when comparing strings, it would be worth to point out that string comparisons in JMESPath will use Unicode codepoints. As a result precomposed characters will not be considered to be equal. |
Beta Was this translation helpful? Give feedback.
-
Ordering Arrays and Strings
AbstractThis JEP standardizes string and array comparisons with respect to the ordering operators. MotivationAlthough JMESPath ordering operators are only defined for numbers, comparing strings is one of the most requested features. When referring to a string as a sequence of Unicode code points, it is intuitive to generalize comparison to arrays. SpecificationOrdering OperatorsOrdering operators Evaluating an element with an expression of any other type with a comparison operator or comparing an element with an expression of a different type altogether will yield a Comparing strings is performed lexicographically, in order of their corresponding sequences of code points. Comparing arrays is performed in order of their elements. For instance, using the For example, given:
The three elements in the The first element resolves to the comparison The final result of that expression is Examples
Compliance TestsNew tests will also be added to the History
|
Beta Was this translation helpful? Give feedback.
-
See: jmespath/jmespath.js#85
Currently, ordering comparison expressions are only valid for numbers.
However, some popular implementations attempt to convert strings to numbers in order to provide a more intuitive behaviour.
Consider the following example:
Some users might write the following expressions:
fruits[? details.size >= `500` ]
to filter all fruits whose size is greater than number500
.fruits[? details.size >= '500' ]
to filter all fruits whose size is greater than string"500"
.Caveat: this might conflict with grammar specification that mandates that no implicit conversion happens unless explicitely specified.
Beta Was this translation helpful? Give feedback.
All reactions