1

This is my api response. Want to extract the value of the Id based on the displayNumber. This display number is a given in the list of values in examples/csv file.

{
  "Acc": [
    {
      "Id": "2b765368696b3441673633325",
      "code": "SGD",
      "val": 406030.83,
      "displayNumber": "8957",
      "curval": 406030.83
    },
    {
      "Id": "4e676269685a73787472355776764b50717a4",
      "code": "GBP",
      "val": 22.68,
      "displayNumber": "1881",
      "curval": 22.68
    },
    {
      "Id": "526e666d65366e67626244626e6266467",
      "code": "SGD",
      "val": 38404.44,
      "displayNumber": "1004",
      "curval": 38404.44
    },
  ],
  "combinations": [
    {
      "displayNumber": "3444",
      "Code": "SGD",
      "Ids": [
        {
          "Id": "2b765368696b34416736333254462"
        },
        {
          "Id": "4e676269685a7378747235577"
        },
        {
          "Id": "526e666d65366e6762624d"
        }
      ],
      "destId": "3678434b643530456962435272d",
      "curval": 3.85
    },
    {
      "displayNumber": "8957",
      "code": "SGD",
      "Ids": [
        {
          "Id": "3678434b6435304569624357"
        },
        {
          "Id": "4e676269685a73787472355776764b50717a4"
        },
        {
          "Id": "526e666d65366e67626244626e62664679"
        }
      ],
      "destId": "2b765368696b344167363332544",
      "curval": 406030.83
    },
    {
      "displayNumber": "1881",
      "code": "GBP",
      "Ids": [
        {
          "Id": "3678434b643530456962435275"
        },
        {
          "Id": "2b765368696b3441673"
        },
        {
          "Id": "526e666d65366e67626244626e626"
        }
      ],
      "destId": "4e676269685a7378747d",
      "curval": 22.68
    },
  ]
}

Examples
|displayNumber|
|8957|
|3498| 
|4943|

Below expression works if i give the value

* def tempid = response
* def fromAccount = get[0] tempid.Acc[?(@.displayNumber==8957].Id

I'm not sure how to make this comparison value (i.e. 1881) as a variable which can be read from examples (scenario outline) or a csv file. Went through the documentation, which recommends, karate filters or maps. However, not able to follow how to implement.

Navneeth
  • 21
  • 1
  • sorry you are asking too many questions here. simplify your question and don't just dump your existing data here. also see this answer, sometimes you shouldn't force yourself to use a `Scenario Outline`: https://stackoverflow.com/a/72388475/143475 – Peter Thomas May 30 '22 at 03:43
  • 1
    Thanks Peter.. for taking time out to clarify. It helped. – Navneeth Jun 11 '22 at 16:25

1 Answers1

0

You almost got it :-). This is the way you want to solve this

Scenario Outline: Testing SO question for Navneeth
* def tempid = response
* def fromAccount = get[0] tempid.Acc[?(@.displayNumber == <displayNumber>)]
* print fromAccount

Examples:
|displayNumber|
|8957|
|1881|
|3444|

You need to pass the placeholder in examples as -

'<displayNumber>' 
Dinesh Arora
  • 2,115
  • 3
  • 24
  • 30