7

I try to use JsonPath to extract values from attributes at different levels of my json object.

Here's my object:

{
    "A": [
        {
            "B": "0",
            "C": "1",
            "D": {
                "E" : "2",
                "F" : "3",
            }
        },
        {
            "B": "4",
            "C": "5",
            "D": {
                "E" : "6",
                "F" : "7",
            }
        }
    ]
}

And I would like to extract in the same time the B and the E values

to get the B, easy : $.A[*].B

to get the E, easy : $.A[*].D.E

to get B and C, easy using the Bracket-notated children operator : $.A[*]['B', 'C']

But to get B and E in the same time, I don't get the correct expression. I expect to have :

[ 
  { "B":"0", "E" : "2"}, 
  { "B":"4", "E" : "7"} 
]

Does someone have the correct expression?

Thanks

E.

Ed Be
  • 79
  • 1
  • StackOverflow is neither a forum, tutorial site nor web search replacement. We can [help with certain problems](https://stackoverflow.com/help/on-topic), but it's **your** job to [put some efforts](http://meta.stackoverflow.com/questions/261592) in the first place, including elementary [(re)search](https://google.com/). Read [how to ask perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and [how to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) then edit your question accordingly, sharing your current approach. – Marcin Orlowski Sep 12 '17 at 15:20
  • I'm trying to find a similar solution, any luck yet? – BinaryShrub Jan 15 '18 at 17:13
  • I disagree with Marcin Orlowski, this is a perfectly worded question. And in fact I was just about to post this precise question. To echo BinaryShrub... any luck yet? :) – Kevin Pauli Dec 19 '18 at 16:58
  • The Closest Query you can try would be `$.A..[*]['B','E']` – Akshay G Dec 17 '21 at 06:57

0 Answers0