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

extract (print) parent attribute when filtering on child node attribute #70

Open
Lcstyle opened this issue Oct 22, 2018 · 1 comment
Open

Comments

@Lcstyle
Copy link

Lcstyle commented Oct 22, 2018

I have a json data structure that looks like this:


{    "version": "14",
    "data": {
"applications": [
{

"id": 1,
                "enabled": true,
                "policy": [
                ]
            },            
{
                "id": 2,
                "enabled": true,
                "policy": [
                    {
                        "type": "Rule",
                        "id": 5
                    }
                ]
            }
]

}

I am trying to return the ID of the application when policy id = 5 (or some other int value).

I thought that: $.data.applications[@.policy.*.id is 5].id would work, but i get an empty set []
I also tried: $.data.applications[@.policy..id is 5].id

using "jq" i can do the following:


#cat jsonData.json  | jq ‘.data.applications[] | select(.policy[].id == 5) | .id’

13
14
15
16
17
18
19
21
22
23
24
39

Is this query functionality not possible using objectPath?

@adriank
Copy link
Owner

adriank commented Oct 22, 2018 via email

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

No branches or pull requests

2 participants