0

Given the following JSON:

[
  {
    "json": {
       "buildInfo": [
         {
           "first": "James",
           "last": "d"
         },
         {
           "first": "James2",
           "last": "d2"
         }
       ]
     },
     "status": 200
   },
   {
    "json": {
       "buildInfo": [
         {
           "first": "Jacob",
           "last": "e"
         },
         {
           "first": "Jacob2",
           "last": "e2"
         }
       ]
    },
    "status": 200
  }
]

I am trying to query the inner list key json.buildInfo."last" for a value to then extract an number of key value ie json.buildInfo.*."first". HOwever I am struggling to get this to work.

I can find the data using a flattening operator...

[*].json.build[].last[contains(@,`d`)]

...but I cannot work out how to perform a query on this that then allows me to obtain extra information list "first" key. On a json with no inner list on buildInfo, I can do something like

[?json.buildInfo.last==`d`].json.buildInfo.first

The switch to list of buildInfo items is proving challenging.

Can someone provide me an guidance here?

Thanks

Gareth
  • 89
  • 1
  • 3
  • I just got this to work for the query [?json.buildInfo[?contains(last,`d2`)]], but then I am not sure how I extract just the one matching block the d2 matches to as the above appears to return the entire buildInfo block containing it which inlcudes the other one also. – Gareth Dec 06 '19 at 13:50

1 Answers1

0

OK this works - but not sure I know why...

[?json.buildInfo[?contains(last,'d2')]].json.build_info[]|[?last=='d'].first

Gareth
  • 89
  • 1
  • 3