Skip to content
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

Support slice operator #312

Open
mainians opened this issue Apr 12, 2023 · 3 comments
Open

Support slice operator #312

mainians opened this issue Apr 12, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@mainians
Copy link

No description provided.

@mainians mainians added the enhancement New feature or request label Apr 12, 2023
@TomWright
Copy link
Owner

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

@mainians
Copy link
Author

mainians commented May 7, 2023

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:]'

@TomWright
Copy link
Owner

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:])`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants