1

I'm using fs.createWriteStream() to add JSON-data asynchronously to a file with file.write(JSON.stringify(data) + ","). So every json-object is followed by a comma. How can I avoid/remove the comma after the last json-object inside the code?

{"key1":"value1"}, {"key2":"value2"},
Dennis L
  • 11
  • 1
  • If it's really `JSON` then `object`s will already be delimited by commas. `JSON.stringify(data) + ","` adds a comma to the end of your stringified `data`. – ethane Mar 20 '19 at 13:24
  • You need to add a condition on the last json-object check is it last or not, if it is last then don't place the comma in the end. – Adnan Ahmed Ansari Mar 20 '19 at 13:39
  • Is your JSON data really more than 1GB? Or are you running your software on a really small machine with only 500MB RAM? – slebetman Mar 20 '19 at 14:21

0 Answers0