Skip to content

Add %J console format specifier

This pull request adds %J format specifier for printing indented JSON.

I believe there may be some appetite for achieving this without cumbersome console.log(JSON.stringify(a, null, 2)). Some representative github code searches:

  • "console.log(" "JSON.stringify(" 3.5mil JS results
  • "console.log(" "%j" 1.1mil JS results
  • "console.dir(" 300k JS results

Actually, now that I look at previous github issues this exact idea was mentioned in https://github.com/nodejs/node/pull/14558. The controversial %o format specifier does seem to be getting a lot of use, as far as I can tell with github code search. Thoughts?

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading