When you read a JSON file, change the key or value, and write back to the same file, you will lose the JSON formatting.

For example:

{
   "a": 1,
   "b": 2,
   "c": 3
} 

You get

{"a":1,"a":2,"a":3}

Here is a way to pretty print JSON using JSON.stringify. JSON.stringify accepts a third parameter which defines white-space insertion. It can be a string or a number (number of spaces). Example:

JSON.stringify({ a:1, b:2, c:3 }, null, 4);
/* output:
{
   "a": 1,
   "b": 2,
   "c": 3
}
*/