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

RFE: parent(n) to get n-th parent #1970

Closed
ryenus opened this issue Mar 7, 2024 · 2 comments
Closed

RFE: parent(n) to get n-th parent #1970

ryenus opened this issue Mar 7, 2024 · 2 comments

Comments

@ryenus
Copy link
Contributor

ryenus commented Mar 7, 2024

Please describe your feature request.

Allow parent to take an optional number argument , to return the nth parent, so . | parent(2) would be the same as . | parent | parent

Describe the solution you'd like
If we have data1.yml like:
(please keep to around 10 lines )

a:
  b:
    c: 1

And we run a command:

yq '.a.b.c | parent(2)'

it could output

b:
  c: 1

Describe alternatives you've considered

parent(2) should work just the same as parent | parent, similarly parent(n) would be the same as parent | parent | ... | parent, just much more concise and clean than the latter.

@ryenus ryenus changed the title RFE: parent(n) RFE: parent(n) to get n-th parent Mar 7, 2024
mikefarah added a commit that referenced this issue Mar 11, 2024
@mikefarah
Copy link
Owner

I like it - will be available in the next release

@mikefarah
Copy link
Owner

Fixed in v4.43.1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants