0
 {
"name": "ninja",
"contry": "India",
"Account": [
{
  "id": "123",
  "orgId": 223,
  "investment": [
    {
      "invetmentId": "111",
      "name": "India tech",
      "performance": [
        {
          "id": "123",
          "performanceSet": [
            {
              "amount": "231",
              "currency": "USD"
            },
            {
              "amount": "250",
              "currency": "IND"
            }
          ]
          
        }
      ]
    }
   ]
 }
]
}

So I have to select the amount where the currency is USD?

And I tried it as "$.Account..investment.performance..performanceSet.amount[?(@.currency=~/.*USD/)]"

Ninja
  • 433
  • 3
  • 10
  • $.Account..investment..performance..performanceSet..[?(@.currency=~/.*USD/)].amount will this be fine ? – Ninja Jul 29 '20 at 10:50

3 Answers3

3

This JsonPath should work:

$..performanceSet[?(@.currency == "USD")].amount

Tested on:

{
   "name":"ninja",
   "contry":"India",
   "Account":[
      {
         "id":"123",
         "orgId":223,
         "investment":[
            {
               "invetmentId":"111",
               "name":"India tech",
               "performance":[
                  {
                     "id":"123",
                     "performanceSet":[
                        {
                           "amount":"231",
                           "currency":"USD"
                        },
                        {
                           "amount":"250",
                           "currency":"IND"
                        }
                     ]
                  }
               ]
            },
            {
               "invetmentId":"112",
               "name":"India tech 2",
               "performance":[
                  {
                     "id":"124",
                     "performanceSet":[
                        {
                           "amount":"235",
                           "currency":"USD"
                        },
                        {
                           "amount":"250",
                           "currency":"IND"
                        }
                     ]
                  }
               ]
            }
         ]
      }
   ]
}

which returns:

[
  "231",
  "235"
]

A good way to try it out is this site: https://jsonpath.com/

pavelsaman
  • 7,399
  • 1
  • 14
  • 32
2

Read the docs: https://github.com/intuit/karate#jsonpath-filters

* def temp = $..performanceSet[?(@.currency=='USD')]
* match temp[0].amount == '231'
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
0

You can try it this way

$.Account..investment.performance..performanceSet.amount[?(@.currency=~/.*USD/)]