I am trying to drill down and extract values (in order to verify them) from a REST service response formatted as shown in the example below:
{
"data": [
{
"A9001001A23D10A943E48481": {
"id": "A9001001A23D10A943E48481",
"type": "WIP",
"status": "ERROR",
"message": "could not move document",
"details": [
"No document found with document id 'A9001001A23D10A943E48481'"
]
}
},
{
"A9001001A23D10A945468483": {
"id": "A9001001A23D10A945468483",
"type": "WIP",
"status": "ERROR",
"message": "could not move document",
"details": [
"No document found with document id 'A9001001A23D10A945468483'"
]
}
}
],
"error": {}
}
I need to compare actual values for id, type, status, message, and details with the expected values. I do know the id # but need to make sure the other values are correct in the response.
I can get the objects in the data[] array (data[0] and data[1]), but have failed completely to get anything below that. I’ve tried putting the array object into a map like so, but that doesn’t get me very far.
let myMap = new Map(Object.entries(jsonData.data[0]));
2
Answers
In general you could use a loop to iterate through the array and accessing the
properties of each object.
Would be great if you could extend your question with what result you are trying to get, like @Unmitigated commented.
Here is some code you could try: