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

145
Views
Extraer y analizar JSON enorme incompleto en NodeJS

Imagine un escenario en el que tengo un archivo JSON enorme en una esencia de Github. Ese JSON es una matriz de objetos y tiene más de 30k líneas. Ahora quiero realizar ETL (Extraer, Transformar, Cargar) esos datos directamente desde Github gist a mi base de datos. Desafortunadamente, el último objeto de ese JSON está incompleto y no tengo ningún control en la fuente de datos externa. Lo que significa que, en una demostración simple, obtengo los datos de esta manera:

[{ "name": { "first": "foo", "last": "bar" } }, { "name": { "first": "ind", "last": "go

¿Cuál es la mejor práctica o cómo puedo extraer un archivo JSON tan grande y analizarlo correctamente en NodeJs?

Intenté analizar usando JSON.parse() regular y un paquete npm llamado "parcial-json-parser" pero no fue de ayuda.

Editar

Encontré una solución de una fuente externa que resuelve problemas de JSON y ETL incompletos. Estoy pegando ese fragmento aquí:

 import fetch from "node-fetch"; import StreamArray from "stream-json/streamers/StreamArray.js"; const main = async () => { const invalidJSON = await fetch( "<raw_gist_array_of_objects_api_endpoint>" ).then((r) => r.body); const finalData = []; const pipeline = invalidJSON.pipe(StreamArray.withParser()); pipeline.on("data", (data) => { finalData.push(data.value); }); await new Promise((r) => { pipeline.on("end", r); pipeline.on("error", r); }); console.log(finalData); }; main();
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Creo que primero debes arreglar la estructura JSON. Solo prueba este enfoque:

 import untruncateJson from "untruncate-json"; const str = `[{ "name": { "first": "foo", "last": "bar" } }, { "name": { "first": "ind", "last": "go`; const fixJson = untruncateJson.default; const json = fixJson(str); console.log(json);
about 4 years ago · Santiago Trujillo Report

0

Creo que puedes analizar datos solo cuando arreglaste la estructura

ejemplo:

 const result = [ { name: "john", gender: "male", }, { name: "doe",

Puede corregir los datos agregando algunos corchetes faltantes

 result += ` gender: "male" } ] `
about 4 years ago · Santiago Trujillo 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!