1

I am writing a JSON file using NodeJS, like this:

var path = "D:\\test.json"
var writeContent = {"Success" : "This is a sample"}
fs.writeFile(path, JSON.stringify(writeContent, null, 4), function (error) {
        if (error === null) {
            response.json(SuccessResponse);
        }else{
            response.json(ErrorResponse + error.message);
        }
    });

The file is getting written successfully, and also the JSON file is pretty printed when I open the JSON file in latest file editors such as Subllime3, Notepad++ I am able to view the pretty form of the file. But when I open the same file in Notepad, I am not able to view the content in the pretty format.

It is viewed as:

{    "GlobalName": "CIRCULAR_GRATES_M01_METRIC",    "LocalName": "Circular Grates M01"    }
1

1 Answer 1

4

The file most likely has UNIX line breaks (\n), as opposed to Windows line breaks (\r\n). Notepad is rather dumb and only supports the latter.

Wordpad, on the other hand, supports both. This is not a joke. ;)

Most “modern” editors support both and allow conversion between the two (and possibly Mac line breaks).

1
  • 1
    Since 2001, Mac OS X line breaks are Unix line breaks, 0x0a aka \n aka LF. (OS 9 and earlier used 0x0d aka \r aka CR.)
    – Arjan
    Commented Aug 24, 2015 at 17:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .