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

169
Vistas
Transform nested JS object AST to another using mapping

I want to transform a nested JS object in AST structure into another using mappings, It can be any level deep. Any help is deeply appreciated. We can use lodash as well if that is convenient.

Motivation :- Supply data can be in several formats, I need to create standard products using different supply objects, for which we can create standard product model and several mappings for product model to supply.

If you think this problem can be solved with a better data modeling of product model or map model, I 'll highly appreciate the suggestions. The supply model is fixed nonetheless.

Data

const source = {
  a:1,
  b:2,
  c:7,
  children:[
    {
      a:3,
      b:7,
      d:8,
      children: [
        {
          a:6,
          b:8,
          x:4
        }
      ]
    },
    {
      a:5,
      b:3,
      c:9
    }
  ]
}

Mappings

const map = {
  c:'a',
  d:'b',
  elements: {
    identifier:'children', // which field to lookout for children
    ofType: 'map' // every child has similar structure as parent
  }
}

Here is the output i am expecting

const output = {
  c:1,
  d:2,
  elements:[
    {
      c:3,
      d:7,
      elements:[
        {
          c:6,
          d:8
        }
      ]
    },
    {
      c:5,
      d:3
    }
  ]
}
about 4 years ago · Juan Pablo Isaza
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