Ninja
Ninja

Reputation: 453

How to get this using json path?

{
"store": {
    "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
        },
        {
            "category": "fiction",
            "author": "Herman Melville",
            "title": "Moby Dick",
            "isbn": "0-553-21311-3",
            "price": 8.99
        },
        {
            "category": "fiction",
            "author": "J. R. R. Tolkien",
            "title": "The Lord of the Rings",
            "isbn": "0-395-19395-8",
            "price": 22.99
        }
    ],
    "bicycle": {
        "color": "red",
        "price": 19.95
    }
},
"expensive": 10
}

What if I need both author and title of all the books? Like rather than having the complete data about the book if I only want some detail of it how can I get that?

Upvotes: 1

Views: 154

Answers (1)

Jack Fleeting
Jack Fleeting

Reputation: 24930

Depending on the implementation, this

$..book[*]['title','author']

should get you close enough.

Upvotes: 5

Related Questions