Strange jsonpath not able to capture (Gatling/Scala)

I have a responsebody that looks like this:

[
  {
    "system": "http://snomed.info/sct",
    "code": "735938006",
    "display": "akutt hodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "267096005",
    "display": "frontal hodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "103011009",
    "display": "godartet anstrengelseshodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "25064002",
    "display": "hodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "38823002",
    "display": "hodepine med aura"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "193031009",
    "display": "klasehodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "230465000",
    "display": "migrene med aura uten hodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "330007",
    "display": "oksipital hodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "54012000",
    "display": "posttraumatisk hodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "4969004",
    "display": "sinushodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "398057008",
    "display": "tensjonshodepine"
  },
  {
    "system": "http://snomed.info/sct",
    "code": "128187005",
    "display": "vaskulær hodepine"
  }
]

and I want to capture the value "hodepine" element 3 from the top. I use IntelliJ and "Copy JSON Pointer" and it gives me this:

/3/display

This does not work using it in Gatling/Scala like this:

.check(jsonPath("$../3/display").saveAs("display"))

The error is:

> jsonPath($../3/display).find.exists, found nothing 

Any tips on how to obtain the value?

>Solution :

I have the answer on similar question and it can be helpful for you.

For your case: $.[3].display

Leave a Reply