String Slices #26
-
Taken from this discussion |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Should we support the |
Beta Was this translation helpful? Give feedback.
-
String Slices
AbstractThe original JEP 5 introduced This JEP introduces changes to allow MotivationString manipulation functions are a frequently requested feature to be added to JMESPath. While introducing a whole host of string manipulation functions will certainly be proposed at some point, slicing strings is an easy extension to JMESPath that does not require any grammar change and is fully backwards compatible. SlicesThis section outline word changes to the Slices documentation of the grammar in bold. slice-expression = [number] ":" [number] [ ":" [number] ] A slice expression allows you to select a subset of an array or string. A slice has a
Given a
Slice expressions adhere to the following rules:
ExamplesSlicing operates on a strings exactly as if a string were thought of as an array of characters.
Compliance testsA new HistoryN/A |
Beta Was this translation helpful? Give feedback.
-
There is an important caveat to this JEP ! Currently, Consider:
This does not seem to be the behaviour we want when applied to strings.
|
Beta Was this translation helpful? Give feedback.
There is an important caveat to this JEP !
Currently,
slice-expression
is a projection, which means that the resulting items being sliced are projected to the downstream expressions.Consider:
search( [::].length(@), ["one", "two", "three"] ) -> [ 3, 3, 5 ]
This does not seem to be the behaviour we want when applied to strings.
Do we really want to have two different behaviours here 🤔 ?
Which of the following two results should be correct ?
search( [::].length(@), "one" ) -> [ 1, 1, 1 ]
search( [::].length(@), "one" ) -> 3
(expected result ?)