Skip to content

JSON Stringify indentation not working #10995

Description

@adi-works
  • Version: 7.4.0
  • Platform: Windows (64-bit)

It appears this doesn't work anymore:

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

Output stays minified.

Activity

  1. vsemozhetbyt commented on Jan 25, 2017

    @vsemozhetbyt
    Contributor

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

    console.log(JSON.stringify({name: 'test'}, null, 4));
  2. mscdex commented on Jan 25, 2017

    @mscdex
    Contributor

    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 ?

  3. added
    questionIssues asking questions about Node.js.
    on Jan 25, 2017
  4. osmanmesutozcan commented on Jan 26, 2017

    @osmanmesutozcan

    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.

  5. adi-works commented on Jan 26, 2017

    @adi-works
    Author

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

  6. vsemozhetbyt commented on Jan 26, 2017

    @vsemozhetbyt
    Contributor

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

  7. Fishrock123 commented on Jan 26, 2017

    @Fishrock123
    Contributor

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

  8. adi-works commented on Jan 26, 2017

    @adi-works
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions