I have JSON data coming from the API and I want to rename occurrences of the multiple keys. I have tried multiple approaches but no luck so far.
Here's what my data look like roughly
{
"9ba698a4-d54c-448c-a216-10d52ed2a5a5":{
"name":"x",
"data":{
"2021-05-04":{
"Amazon Simple Storage Service":123,
"Amazon Elastic Compute Cloud - Compute":123,
"sum":123,
"credits":{
"total":-123,
"Amazon Simple Storage Service":-123,
"Amazon Elastic Compute Cloud - Compute":-123
}
},
"2021-05-07":{
"Amazon Simple Storage Service":123,
"Amazon Elastic Compute Cloud - Compute":123,
"sum":123,
"credits":{
"total":-123,
"Amazon Simple Storage Service":-123,
"Amazon Elastic Compute Cloud - Compute":-123
}
},
"services":[
"Amazon Simple Storage Service",
"Amazon Elastic Compute Cloud - Compute"
],
"total":123,
"credits_total":-123
}
}
}
In the provided data, I would like to change all the instances of "Amazon Simple Storage Service" to "S3" and "Amazon Elastic Compute Cloud - Compute" to "EC2". What are the possible ways I can modify the nested data inside the object?
To work around that, I tried to modify the DOM with custom JS something like:
document.body.innerHTML = document.body.innerHTML.replace("Amazon Elastic Compute Cloud - Compute", "S3");
It's working as expected but since I am passing the object to chart JS it's not updating the occurrences on the Chart.
Any guide/help would be highly appreciated.