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

212
Visualizações
How to flatten nested Json dynamically on snowflake or javascript?

This is an example of the JSON file I'm working with, it has around 600 rows of the same nested JSON structure.

{
  "at": {
    "Availability": "Yes",
    "Message": "NV",
    "Delivery option": "fast",
  },
  "childNodeIds": [],
  "crawlMessageFlags": null,
  "pd": {
    "product_id": "product_id value",
    "product_name": "product_name value",
    "retailerName": "retailerName value",
    "stock_status": "InStock",
    "subClassName": "n/a"
  },
  "sellers": [],
  "zipDetails": {}
}

I want to generate a report that has the keys inside PD as the column names. Example

--------------------------------------------------------
    product_id  |   product_name     | retailerName
-----------------------------------------------------------
productid value1| product_name value1| retailerName value1
productid value2| product_name value2| retailerName value2
productid value3| product_name value3| retailerName value3
productid value4| product_name value4| retailerName value4

I can generate this table with hardcoded values but I want to do it dynamically as we have several different use cases.

I have tried several solutions from the web but none solves this without hardcoding.

Any solutions?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's one approach that might work for you. Depending on the structure of the resulting variable (output) you might want to refactor accordingly.

const list = [
  {
  "at": {
    "Availability": "Yes",
    "Message": "NV",
    "Delivery option": "fast",
  },
  "childNodeIds": [],
  "crawlMessageFlags": null,
  "pd": {
    "product_id": "product_id value1",
    "product_name": "product_name value1",
    "retailerName": "retailerName value1",
    "stock_status": "InStock 1",
    "subClassName": "n/a"
  },
  "sellers": [],
  "zipDetails": {}
},
  {
  "at": {
    "Availability": "Yes",
    "Message": "NV",
    "Delivery option": "fast",
  },
  "childNodeIds": [],
  "crawlMessageFlags": null,
  "pd": {
    "product_id": "product_id value2",
    "product_name": "product_name value2",
    "retailerName": "retailerName value2",
    "stock_status": "InStock 2",
    "subClassName": "n/a"
  },
  "sellers": [],
  "zipDetails": {}
}
]

const output = list.reduce((acc,{ pd })=>{
  acc.push([ pd.product_id, pd.product_name, pd.retailerName ])
  return acc;
}, [["product_id", "product_name", "retailerName"]]);


console.log( output );

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