jsonpath icon indicating copy to clipboard operation
jsonpath copied to clipboard

exclude fields

Open antonioaltamura opened this issue 9 years ago • 2 comments

Hi, I'm going to build a part of my nodejs application using this module. I hope it fits my needs. I have a pretty big tree in json. If I query the first book $..book[0] I would like to exclude specific fields, for example the price. Like this result

               {
                    "category": "reference",
                    "author": "Nigel Rees",
                    "title": "Sayings of the Century"
                }

In XPath there are ways, how about here?

var db = {
        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
            }
        }
    };

antonioaltamura avatar Sep 30 '16 23:09 antonioaltamura

@dchester I'm interested in this kind of thing too. Is there a way to get a query to return authors and titles as pairs?

$..book[?(@.category=="fiction")].[author&title]

I don't think that this is possible at the moment - is there a way to add a custom reducer or would you consider it?

Fantastic library btw, the docs are spot on, really easy to understand

bapti avatar Feb 04 '17 08:02 bapti

Scratch that, read the tests again

"$..book[?(@.category=="fiction")]['author','title']"

bapti avatar Feb 04 '17 09:02 bapti