简体   繁体   中英

Jsonpath: Is there a way to any one of the available child nodes using JsonPath

In JsonPath, i am trying to pick attributes from one of the available json nodes. However, i couldn't come up with an expression. I tried using anyOf, but wasn't successful. For instance, i need to pull books from any one of the stores (A or B). I am not interested from which store the books get picked up. Please help.

    "storeA": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            }
        ]
    },
    "storeB": {
        "book": [
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "action",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ]
    }
}```

I think you're looking for the wildcard selector. I'm not sure how your Java implementation would do it specifically, but the path for it is $.*.book ...

The wildcard property selector .* does the trick. It'll pick up all properties of the object.

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