简体   繁体   中英

Jsonpath for array of objects with nested arrays

I am trying to write a jsonpath for following object:

{
    "ParentArray": [
        {
            "ChildArray": [
                {
                    "ChildArrayObjectKey": "ChildArrayObjectValue1"
                },
                {
                    "ChildArrayObjectKey": "ChildArrayObjectValue2"
                }
            ]    
        },
        {
             "ChildArray": [
                {
                    "ChildArrayObjectKey": "ChildArrayObjectValue3"
                },
                {
                    "ChildArrayObjectKey": "ChildArrayObjectValue4"
                }
            ]  
        }  
    ]
}

Which would extract the object from the ParentArray. I am looking for an object which contains a value 'ChildArrayObjectValue3' in its ChildArray. The solution I think should work is:

$.ParentArray[?(@.ChildArray[?(@.ChildArrayObjectKey === 'ChildArrayObjectValue3')])]

But unfortunately it does not provide any results. What I would like to extract is:

{
    "ChildArray": [
        {
            "ChildArrayObjectKey": "ChildArrayObjectValue3"
        },
        {
            "ChildArrayObjectKey": "ChildArrayObjectValue4"
        }
    ]  
}

试试这种方式:$ .ParentArray .. * [?(@。ChildArrayObjectKey =='ChildArrayObjectValue3')]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM