Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda