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

184
Views
Parse several json.stringify records from one file?

At intervals I am collecting data records that should be stored in append-mode to the end of a certain file; I am using json.stringify to render them as text. Later, when I connect to my server, I want to send all those records to the server. Doesn't look like json.parse is capable of handling more than one record; consecutive records are going to make it unhappy. Is there a well-known solution to this problem?

Here's a test program:

fs = require("fs");

const record1 = {
name: "Sarah",
age: 25
};
const record2 = {
name: "Joseph",
age: 34
};

function write() {
  var t1 = JSON.stringify(record1);
  var t2 = JSON.stringify(record2);
  fs.appendFileSync("test.json", t1);
  fs.appendFileSync("test.json", t2);
}

function read() {
  text = fs.readFileSync("test.json");
  var v1 = JSON.parse(text);
  console.log(v1);
}

write();
read();

Here's the file test.json:

{"name":"Sarah","age":25}{"name":"Joseph","age":34}

and here's the result:

Process exited with code 1
Uncaught SyntaxError: Unexpected token { in JSON at position 25

So what's the best way to come back and read those two separate records?

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!