Node: JSON Stringify indentation not working

Created on 25 Jan 2017  路  7Comments  路  Source: nodejs/node

  • Version: 7.4.0
  • Platform: Windows (64-bit)

It appears this doesn't work anymore:

JSON.stringify({name: 'test'}, null, 4)

Output stays minified.

question

Most helpful comment

Ok, found the culprit. I had a JSON.stringify polyfill that messed it up. So sorry.

All 7 comments

If you try this simple evaluation in REPL, you will get a 'debug` output. Try this:

console.log(JSON.stringify({name: 'test'}, null, 4));

It works for me:

> JSON.stringify({name: 'test'}, null, 4)
'{\n    "name": "test"\n}'
> console.log(JSON.stringify({name: 'test'}, null, 4))
{
    "name": "test"
}
undefined
> 

Is that what you're seeing @adi518 ?

Here also works:

> JSON.stringify({name: 'test'}, null, 4)
'{\n    "name": "test"\n}'
> console.log(JSON.stringify({name: 'test'}, null, 4))
{
    "name": "test"
}
undefined
>

Platform: macOS.

Nope, still doesn't work whatsoever. It used to work just fine some months ago.

@adi518 Could you please describe in detail how do you launch the code and what output you get literally?

@adi518 can you try it in the REPL? (Launch node without a file)

Ok, found the culprit. I had a JSON.stringify polyfill that messed it up. So sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Icemic picture Icemic  路  3Comments

stevenvachon picture stevenvachon  路  3Comments

mcollina picture mcollina  路  3Comments

akdor1154 picture akdor1154  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments