yq
yq copied to clipboard
Add Array/String Slice
Add support for Array/String Slice
The .[10:15] syntax can be used to return a subarray of an array or substring of a string. The array returned by .[10:15] will be of length 5, containing the elements from index 10 (inclusive) to index 15 (exclusive). Either index may be negative (in which case it counts backwards from the end of the array), or omitted (in which case it refers to the start or end of the array).
Expected
a: Easy! as one two three
b:
c: 2
d: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
e:
- name: fred
value: 3
- name: sam
value: 4
$ yaml r sample.yaml b.d[2:5]
- 5
- 6
- 7
- 8
@mikefarah, possible to revisit this? Any chance to resurrect?
This is really helpful in case the input is not strictly json for jq to accept, meanwhile ok for yq. so, instead of first passing the input array data first to yq, and normalized for jq to extract the wanted slice of the array. It would be great to be able to process the data just once in yq and extract the array slice in place, especially when the amount of input data is large.
@mikefarah was this closed unintentionally? No comments or commits were ever made.
Oops - sorry yeah closed unintentionally.
Fixed (finally) in 4.29.1