Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda