0

How do i write an expression to obtain the value "lastUpdated" in the below json response data

{"resourceType":"Parameters","parameter":[{"name":"medication","resource":{"resourceType":"Bundle","id":"956ffe6a-08ed-4cb6-82ca-41065a4a9923","meta":{"lastUpdated":"2020-08-24T19:09:18.5649325+00:00",

I have tried this but it does not work:

regex("\"lastUpdated\": \"(.*?)\"").saveAs("lastUpdated")

this also does not work:

jsonPath("$..[?(@.use==\"lastUpdated\")].value").saveAs("lastUpdated"))
Magnus Jensen
  • 905
  • 6
  • 36
  • 73

1 Answers1

0

Your input is a little cut off but here is what I've got:

myJSONString = '{"resourceType":"Parameters","parameter":[{"name":"medication","resource":{"resourceType":"Bundle","id":"956ffe6a-08ed-4cb6-82ca-41065a4a9923","meta":{"lastUpdated":"2020-08-24T19:09:18.5649325+00:00"}}}]}'
myJSONObject = JSON.parse(myJSONString)
myLastUpdated = myJSONObject.parameter[0].resource.meta.lastUpdated
console.log(myLastUpdated)

Basically you convert it from a json object into a javascript object. Then you can just traverse down the tree to your intended target.

  • Thanks, but I cannot use (I think) use a java function like that. I am using Gatling tool writing scala code and I allready have something that works using it like this: .check(jsonPath("$..[?(@.name==\"KJFeilkode\")].valueCodeableConcept.text").is("OK")) on the same json response body. So maybe I need to construct it somewhat similar? As in .check(jsonPath("$.parameter[0].resource.meta.lastUpdated")].value.saveAs( "lastUpdated" )) ? – Magnus Jensen Aug 25 '20 at 04:57