I have JSON data in array variable and I want to update some value in this array by string keys. Here is what's my array look like:
{
"all": [
{
"image":{
"URL":"img/img1.jpeg",
"font": "sfsdfsdf",
"color": "sfsdfs"
},
"music": {
"URL":"fsfsfd",
"time": {
"start":"sfsdf",
"end":"qdqsd"
}
}
},
{
"image":{
"URL":"img/img2.jpeg",
"font": "sfsdfsdf",
"color": "sfsdfs"
},
"music": {
"URL":"fsfsfd",
"time": {
"start":"sfsdf",
"end":"qdqsd"
}
}
}
]
}
I have a second array with the path splitted of the key I want to update like this:
var path = ["all", 0, "image", "font"]
For the moment I just loop path
variable and search in my JSON data if the key exist.
But I have absolutly no idea how to update my JSON array without altering the schema of the array...
For example I want to replace myArray[all][0][image][font]
value by "My Other Value"
The final goal is to have my JSON array updated and rewrite a JSON file.
EDIT :
I found the solution here : Dynamically updating a JavaScript object from a string path