Sachin Arora
Sachin Arora

Reputation: 23

How can I extract response from json array in Karate

I am trying to extract response[0].otpValue but it does not work

I have tried to:

get[0] response.id
response[0].otpValue
{
    "errorCode": null,
    "response": [
        {
            "createdTimestamp": 1557314537720,
            "lastUpdatedTimestamp": 1557314537720,
            "createdBy": null,
            "lastUpdatedBy": null,         
            "otpValue": "5346",
            "expiryTimestamp": 1556807308797,
            "validNow": false,
            "sessionUserId": null
        }
    ],
    "status": "SUCCESS",
    "errorMessage": null
}

I am looking to get otpValue from above json response

* def firstOtp = response[0].id

Upvotes: 1

Views: 664

Answers (1)

Adrien
Adrien

Reputation: 1090

* def answer = { "errorCode": null, "response": [ { "createdTimestamp": 1557314537720, "lastUpdatedTimestamp": 1557314537720, "createdBy": null, "lastUpdatedBy": null, "otpValue": "5346", "expiryTimestamp": 1556807308797, "validNow": false, "sessionUserId": null } ], "status": "SUCCESS", "errorMessage": null }
* def firstOtp = answer.response[0].otpValue
* match firstOtp == "5346"

Upvotes: 1

Related Questions