I have the following object:
const jj = {
"type": "doc",
"content": [{
"type": "paragraph",
"content": [{
"type": "text",
"text": "HI \n"
}, {
"type": "text",
"marks": [{
"type": "link",
"attrs": {
"href": "https://infosysta-my.sharepoint.com/:x:/p/elie%5Fiskandar/EXmik99OQBBNiJua1zbbiUIBwU8QEVOzyXl3qRV3ZnhADw",
"__confluenceMetadata": null
}
}],
"text": "Client List - MW.xlsx"
}]
}, {
"type": "paragraph",
"content": [{
"type": "text",
"text": "regards,"
}]
}],
"version": 1
};
I need to remove the "__confluenceMetadata":null key/value so the new object will be:
const jj = {
"type": "doc",
"content": [{
"type": "paragraph",
"content": [{
"type": "text",
"text": "HI \n"
}, {
"type": "text",
"marks": [{
"type": "link",
"attrs": {
"href": "https://infosysta-my.sharepoint.com/:x:/p/elie%5Fiskandar/EXmik99OQBBNiJua1zbbiUIBwU8QEVOzyXl3qRV3ZnhADw"
}
}],
"text": "Client List - MW.xlsx"
}]
}, {
"type": "paragraph",
"content": [{
"type": "text",
"text": "regards,"
}]
}],
"version": 1
};
I tired to iterate through the elements using let arr = Object.entries(ADFDocJson); but I couldn't reach what I needed.
I am looking for a generic method to use as this is just an example object and there might be multiple objects in the marks array.
Presented below is one possible way to achieve the desired objective.
Code Snippet
const removeMeta = argObj => (
Object.fromEntries(
Object.entries(argObj)
.map(([k, v]) => (
k !== 'content'
? ([k, v])
: ([k, (
v.map(ob1 => (
!('content' in ob1)
? ({...ob1})
: ({...ob1,
content: ob1.content.map(
ob2 => (
!('marks' in ob2)
? ({ ...ob2 })
: ({ ...ob2,
marks: ob2.marks.map(ob3 => (
!('attrs' in ob3 &&
'__confluenceMetadata' in ob3.attrs &&
ob3.attrs['__confluenceMetadata'] === null
)
? ({ ...ob3 })
: ({ ...ob3,
attrs: Object.fromEntries(
Object.entries(ob3.attrs)
.filter(
(
[k2, v2]
) => (
k2 !== '__confluenceMetadata'
)
)
)
})
))
})
)
)
})
))
)])
))
)
);
const jj = {
"type": "doc",
"content": [{
"type": "paragraph",
"content": [{
"type": "text",
"text": "HI \n"
}, {
"type": "text",
"marks": [{
"type": "link",
"attrs": {
"href": "https://infosysta-my.sharepoint.com/:x:/p/elie%5Fiskandar/EXmik99OQBBNiJua1zbbiUIBwU8QEVOzyXl3qRV3ZnhADw",
"__confluenceMetadata": null
}
}],
"text": "Client List - MW.xlsx"
}]
}, {
"type": "paragraph",
"content": [{
"type": "text",
"text": "regards,"
}]
}],
"version": 1
};
console.log(removeMeta(jj));
.as-console-wrapper { max-height: 100% !important; top: 0 }
Explanation
Iterate over the various key-value pairs of the object, and then iterate over the nested 'content' arrays, identify the relevant prop and filter it out.