I am currently trying to parse my response which I am getting from my back end.
My response looks as
{ "status": { "code": 400, "version": "1.0", "Id": "a817817b-79eb-4ceb-994d-b52a9e5d86bb", "errors": [ { "message": "Bad data.", "type": "100001" } ] }, "data": null }
Trying to read the value of "code" from above JSON. My java script code looks as below.
var errorResponse= context.getVariable("response.content"); var httpStatusCode= errorResponse.status.code; context.setVariable('flow.response.http.status.code', httpStatusCode);
The error I got:
Javascript runtime error: "TypeError: Cannot read property "code" from undefined.
Is there a way to read json elements?
Solved! Go to Solution.
You need to JSON parse the response content string. Try below,
var errorResponse= context.getVariable("response.content"); var errorResponseObject = JSON.parse(errorResponse); var httpStatusCode= errorResponseObject.status.code;
context.setVariable('flow.response.http.status.code', httpStatusCode);
You need to JSON parse the response content string. Try below,
var errorResponse= context.getVariable("response.content"); var errorResponseObject = JSON.parse(errorResponse); var httpStatusCode= errorResponseObject.status.code;
context.setVariable('flow.response.http.status.code', httpStatusCode);
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |