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

52
Views
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
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!