Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Removing a specific element from an object that is located inside a parent element

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!