I have an object, i.e.:
{
item1: "value1",
item2: "value2",
item3: {
item4: "value4",
item5: "value5"
}
}
I want to use JSON.stringify
with a replacer
function that will act different on items 4 & 5, the inner properties of item3.
How can that be done ?
something like the following pseudo-code:
return JSON.stringify(obj, (key, val) => {
if (key is child of Item3) {
return someOtherValue;
} else {
return val;
}
}
The desired output is json. i.e.:
{
"item1" : "value1",
"item2" : "value2",
"item3" : {
"item4" : "theSomeOtherValue",
"item5" : "theSomeOtherValue"
}
Edit:
Items 4 & 5 are not known beforehand, they are dynamically generated.
I only know the title for item3
at run time