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

96
Views
Cómo analizar datos JSON anidados complejos en NodeJS

Tengo una especie de JSON anidado complejo en mi dynamoDB, quiero extraer este objeto Filter y sus valores. Por ejemplo, si Type es macBook devuelve el objeto Filter y su valor PRO y AIR . Encuentre mi código a continuación y la entrada JSON. Estoy luchando para analizar estos valores en NodeJS. ¿Alguien podría ayudarme? ¿Cómo obtener el objeto de filtro?

JSON

 { "ProductType": { "S": "Apple" }, "Type": { "M": { "iPhone": { "M": { "Filter": { "M": { "model": { "SS": [ "X", "XS" ] } } } } }, "macBook": { "M": { "Filter": { "M": { "model": { "SS": [ "PRO", "AIR" ] } } } } } } } }

producto.js

 const AWS = require('aws-sdk'); var dynamodb = new AWS.DynamoDB({ region: process.env.AWS_REGION, }); const getModel = function (productType) { return new Promise((resolve, reject) => { var params = { Key: { "ProductType": { S: productType } }, TableName: 'product' }; dynamodb.getItem(params, function (err, data) { if (err) reject(err, err.stack); else { console.log("data: " + Object.keys(data)); let product = data.Item.ProductType.S; let filterModel = data.Item.Type.M console.log(filterModel); } }); }); } getModel('Apple')

Cualquier ayuda sería muy apreciada

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Debe usar Object.values para obtener los valores de los objetos de iPhone y macbook , luego dentro puede usar flatMap para encontrar el Filter que tiene propiedades PRO", "AIR" .

 const data ={ "ProductType": { "S": "Apple" }, "Type": { "M": { "iPhone": { "M": { "Filter": { "M": { "model": { "SS": [ "X", "XS" ] } } } } }, "macBook": { "M": { "Filter": { "M": { "model": { "SS": [ "PRO", "AIR" ] } } } } } } } } const result = Object.values(data.Type.M).flatMap((item) => { const SS = item.M.Filter.M.model.SS return SS.includes('PRO') && SS.includes('AIR') ? [{ Filter: item.M.Filter.M }] : [] }, []) console.log(result)

about 4 years ago · Santiago Gelvez 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!