Save an object array into one text record per array element
03:53 17 Mar 2024

I have an application which, from time to time, saves object arrays into text files. All the elements of the object array display identical structure.

As an example, consider the following object array:

[{"A":1,"B":2},{"A":11,"B":22},{"A":111,"B":222}]

The need is to save this into a file such that it would look like this:

[{"A":1,"B":2} , 
{"A":11,"B":22} , 
{"A":111,"B":222}]

meaning, one record within the text file for each object in the array.

The reason for that is that those arrays may include hundreds and up to several thousands of elements and I wish to keep these files READABLE for humans.

Is there any trick that can be invoked when using the standard JSON.stringify method? I am also open to other approaches.

javascript json stringify