dasel icon indicating copy to clipboard operation
dasel copied to clipboard

Support slice operator

Open ycycxz opened this issue 2 years ago • 6 comments

ycycxz avatar Apr 12 '23 12:04 ycycxz

This is reasonable. The index current index operator has a syntax of:

index(0)
index(0,1,2)
[0]
[0,1,2] <-- I've spotted an issue that could stop this from working, but this is the intended format.

A proposed syntax for the slice operator may be:

slice(1,5), [1...5] - Index 1 through 5
slice(*,5), [*...5] - All indexes up to 5
slice(1,*), [1...*] - Index 1 to the end of the list

Any feedback on this? I'm open to any other syntax that makes sense

TomWright avatar May 07 '23 14:05 TomWright

jq -r '.province[:-1] + .city[:-1]'

.province[:-1] extracts the value of the "province" field and removes the last character .city[:-1] extracts the value of the "city" field and removes the last character The + operator concatenates the modified values together


To remove the first two characters from the "province" and "city" fields using jq, you can modify the command as follows:

jq -r '.province[2:] + .city[2:]'

ycycxz avatar May 07 '23 17:05 ycycxz

We can do something similar. It'll be a little more long form because the join func doesn't have shorthand right now, but something like:

dasel -r json `join(province[2:],city[2:])`

TomWright avatar May 07 '23 23:05 TomWright