Return parent node with jq while querying one of its children Return parent node with jq while querying one of its children unix unix

Return parent node with jq while querying one of its children


The filter in the original question is close to a solution. All that's needed is to rearrange what goes in the select. E.g.

  .DistributionList.Items[]| select(.Origins.Items[].Id == "abc")| .Id


The filter: .. | objects | select(.Origins.Items[]? | .Id == "abc") | .Id

produces:

"parent123"

You might want to parameterize the filter, e.g.:

def parent(child): .. | objects | select( .Origins.Items[]? | .Id == child) | .Id ;