How to extract few elements from json list.

66 views
Skip to first unread message

Krishna Gandra

unread,
Feb 9, 2016, 9:17:15 PM2/9/16
to JsonPath
How do I get few elements from a list, from below list I want to retrieve only category and author fields for all books.

{
    "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
}
                        

kalle stenflo

unread,
Feb 10, 2016, 2:50:02 AM2/10/16
to JsonPath
This will do what you want

$.store.book[*]['author', 'category']

Krishna Gandra

unread,
Feb 10, 2016, 6:04:27 PM2/10/16
to JsonPath
Thanks a lot, it works.
Reply all
Reply to author
Forward
0 new messages