Modify the null objects in a JSON array.
I attempted to use map, but it did not update all the JSON objects.
Here is an example of a JSON array:
var response =
{
"code": null,
"message": "Total 1 records found",
"result": {
"ordersList": [
{
"testId": 134,
"ordersDto": {
"orderId": 51684,
"reportses": [
{
"reportId": 472,
"reportStatus": {
"id": 10,
"value": "Pending",
"prevId": 9,
"type": "R"
}
}
]
}
},
{
"testId": 134,
"ordersDto": {
"orderId": 51687,
"reportses": [
],
}
},
{
"testId": 134,
"ordersDto": {
"orderId": 51689,
"reportses": [
],
}
},
]
}
}
If the 'reports' property is null, then I need to update the 'reportStatus' for all the JSON objects in the array with the following details:
New Object = "reportStatus": {
"id": 10,
"value": "Pending",
"prevId": 9,
"type": "R"
}
After the update, the array will return with the updated status.
var response =
{
"code": null,
"message": "Total 1 records found",
"result": {
"ordersList": [
{
"testId": 134,
"ordersDto": {
"orderId": 51684,
"reportses": [
{
"reportId": 472,
"reportStatus": {
"id": 10,
"value": "Pending",
"prevId": 9,
"type": "R"
}
}
]
}
},
{
"testId": 134,
"ordersDto": {
"orderId": 51687,
"reportses": [
{
"reportStatus": {
"id": 10,
"value": "Pending",
"prevId": 9,
"type": "R"
}
}
],
}
},
{
"testId": 134,
"ordersDto": {
"orderId": 51689,
"reportses": [
{
"reportStatus": {
"id": 10,
"value": "Pending",
"prevId": 9,
"type": "R"
}
}
],
}
},
]
}
}