Suppose I have the following JSON data, which can easily be converted into a JavaScript object:
{
"foo": {
"bar": "Common substitute word",
"baz": "Another common substitute word",
"questionWords": {
"wat": "Inadequate question word",
"wut": "Even more inadequate question word"
}
}
}
Now, I receive modifications for this JSON in another JSON file, like so:
{
"foo.questionWords.wut": "A question word to avoid"
}
The path to modify is provided as a string, and I need to update the original JSON with this new information.
However, there are cases where the new data path may not exist:
{
"foo.callingWords.dude": "Commonly used synonym for pal"
}
Additionally, the new data path could have an unknown depth:
{
"who.knows.how.deep.we.will.go": "Look, a penny!"
}
What would be the most effective way to handle these scenarios using plain Vanilla JavaScript without the use of any libraries?
(Feel free to utilize the latest JavaScript features.)
Thank you for your assistance!