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

56
Visualizações
JSON object is getting corrupted

I am using a JSON object on a project I am working on. I am doing many updates to this JSON file as it is my primary file to work with. I am using nodejs to handle requests and processes my file.

My JSON data looks something like this:

[
   { field1:123,
    field2:"Test",
    field3:"New",
    field4:"City",
   },
   { field1:"123",
    field2:"Test2",
    field3:"FILE to use",
    field4:"Assignment Token",
   }
]

Throughout its life cycle my files gets corrupted and a it show a similar pattern every time it gets corrupted. I tried to reduce as many number of call it is possible. The pattern it shows is as follows. Any ideas how to avoid this?

[
   { field1:123,
    field2:"Test",
    field3:"New",
    field4:"City",
   },
   { field1:"123",
    field2:"Test2",
    field3:"FILE to use",
    field4:"Assignment Token",
   }
]o use",field4:"Assignment Token",}]

The basic pattern I am using to update the file is as such:

app.post('/send-to-waitlist', function(req, res){
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    var reqData = req.body;
    console.log(reqData);
    var cpso = reqData.CPSO;
    try{
      var rawData2 = fs.readFileSync('filepath',{encoding: 'utf8'})
      var data2 = JSON.parse(rawData2);
      var eid = reqData.id;;
      for(let d of data2){
       if(d.eid==eid){
        d.SpecialType="Waiting";
        break;
      }
    }
   fs.writeFileSync('filepath', JSON.stringify(data2));

   res.json({Message: "Data moved Successfully."});
 }catch(e){
        console.log(e);
        res.json({error:e});
    }
})
about 4 years ago · Juan Pablo Isaza
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