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

164
Views
Remove nested json object from main json object with nodejs

Hi I had an Json Object like that

          "clips"[
                {             
                "layers": [
                    {
                        "type": "image-overlay",
                        "path": "http://google.com",
                    },
                    {
                        "type": "slide-in-text",
                        "text": "Some Bags"
                    },
                   
                ]
            },
            {
                "duration": 3,
                "layers": [
                    {
                        "type": "image",
                        "path": "http://google.com",
                        "resizeMode": "stretch",
                        "start": 0,
                        "stop": 3,
                    },
                    {
                        "type": "image-overlay",
                        "path": "***vendor**logo*0",
                        "zoomDirection": "in",
                        "width": 0.7,
                    }
                ]
            }
           ]

I want to remove json object which contain,

*** vendor ** logo*0

So I want to remove only this object:

                    {
                        "type": "image-overlay",
                        "path": "***vendor**logo*0",
                        "zoomDirection": "in",
                        "width": 0.7,
                    }

My code snipped like that:

jsonObj.clips.map((clip, index)=>{
    clip.layers.map((layer, index=>{
         if(layer.path === '***vendor**logo*0'){
           //Remove layer
          }
    })
})

How Can I do this with nodejs? Please Help!

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

0

You could return all other items except the one you don't want

const json = /* your json array */

const newJson = json.map(node => node.layers.filter(layer => layer.path !== "***vendor**logo*0"));
about 4 years ago · Juan Pablo Isaza Report

0

Your question wasn't very clear, so I had to guess a bit. But here is a potential solution using object-scan

Currently, it only works with arrays, but it could easily be generalized. Please let me know if you have any questions.

.as-console-wrapper {max-height: 100% !important; top: 0}
<script type="module">
import objectScan from 'https://cdn.jsdelivr.net/npm/object-scan@18.1.2/lib/index.min.js';

const input = { clips: [{ layers: [{ type: 'image-overlay', path: 'http://google.com' }, { type: 'slide-in-text', text: 'Some Bags' }] }, { duration: 3, layers: [{ type: 'image', path: 'http://google.com', resizeMode: 'stretch', start: 0, stop: 3 }, { type: 'image-overlay', path: '***vendor**logo*0', zoomDirection: 'in', width: 0.7 }] }] };

const rm = (obj, v) => objectScan(['**[*].*'], {
  abort: true,
  rtn: 'bool',
  filterFn: ({ gparent, gproperty, value }) => {
    if (value === v) {
      gparent.splice(gproperty, 1);
      return true;
    }
    return false;
  }
})(obj);

console.log(rm(input, '***vendor**logo*0'));
// => true

console.log(input);
// => { clips: [ { layers: [ { type: 'image-overlay', path: 'http://google.com' }, { type: 'slide-in-text', text: 'Some Bags' } ] }, { duration: 3, layers: [ { type: 'image', path: 'http://google.com', resizeMode: 'stretch', start: 0, stop: 3 } ] } ] }
</script>

Disclaimer: I'm the author of object-scan

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!