I have an object structured like this. It will continue with more children blocks in a similar format. My goal is to replace the value of "date" throughout the entire object with a version processed through NLP.
{
"date": "next friday"
"more text": "someVariable"
"children": [{
"date": "today"
"more text": "someVariable"
"children": [{
"date": "yesterday"
"more text": "someVariable"
"children": []},
{"date": "yesterday"
"more text": "someVariable"
"children": []}]
}
}
My aim is to run a text replacement function solely on the values of "date" within the entire array and return an updated object where everything else remains unchanged, except for the "date" values that successfully undergo the find and replace operation.
This essentially involves applying NLP to the "date" items.
I've made an attempt using a recursive function but I'm struggling to preserve the original structure.
async function parseChildren(obj, child = true){
for (var k in obj)
{if (obj[k] !== null){
// console.log(obj(k))
if (k == "date"){
console.log(obj[k])
console.log(parseDates(obj[k]))
}
if (k == "children"){
parseChildren(obj[k], false)
}
else if (child == false) {
parseChildren(obj[k])
}
}
}
}
Any assistance you can provide would be greatly appreciated!