Have A JSon Array Like This inside my JSON File
{
"userId": "UserIDA",
"SNNO": "1234_1212",
"dateTime": "2023-06-30T06:39:28.3340878+08:00",
"
"Results": [
{
"Order": "1",
"OrderStatus": "Received",
"OrderDetails": [
{
"OName": "Packing",
"OStatus": "22",
"OValue": "24"
},
{
"OName": "INvoice",
"OStatus": "24",
"OValue": "29"
},
{
"OName": "LIst",
"OStatus": "56",
"OValue": "44"
}
]
}
]
}
Through Dynamically i need to modify the values for all the Orderdetails(0,1,2).Plz help
Amit MohantyPosted Jun 30, 2023, 5:26 AM
Brahma Prakash ShuklaPosted Jun 30, 2023, 3:23 AM
To modify the values for all the
OrderDetailsin the given JSON, you can use JavaScript or any other programming language that supports JSON manipulation. Here's an example using JavaScript:// Assuming the JSON data is stored in a variable called jsonData
var jsonData = {
"userId": "UserIDA",
"SNNO": "1234_1212",
"dateTime": "2023-06-30T06:39:28.3340878+08:00",
"Results": [
{
"Order": "1",
"OrderStatus": "Received",
"OrderDetails": [
{
"OName": "Packing",
"OStatus": "22",
"OValue": "24"
},
{
"OName": "INvoice",
"OStatus": "24",
"OValue": "29"
},
{
"OName": "LIst",
"OStatus": "56",
"OValue": "44"
}
]
}
]
};
// Modifying the values for all OrderDetails
jsonData.Results[0].OrderDetails.forEach(function(orderDetail) {
orderDetail.OStatus = "NewStatus";
orderDetail.OValue = "NewValue";
});
// Printing the modified JSON
console.log(JSON.stringify(jsonData, null, 2));