JSON.stringify's third parameter defines white-space insertion for pretty-printing. It can be a string or a number (number of spaces). Node can write to your filesystem with fs. Example:

var fs = require('fs');

fs.writeFile('test.json', JSON.stringify({ a:1, b:2, c:3 }, null, 4));
/* test.json:
{
     "a": 1,
     "b": 2,
     "c": 3,
}
*/

See the JSON.stringify() docs at MDN, Node fs docs

Answer from Ricardo Tomasi on Stack Overflow
🌐
npm
npmjs.com › package › pretty-print-json
pretty-print-json - npm
February 27, 2026 - Latest version: 3.0.7, last published: a month ago. Start using pretty-print-json in your project by running `npm i pretty-print-json`. There are 13 other projects in the npm registry using pretty-print-json.
      » npm install pretty-print-json
    
Published   Feb 27, 2026
Version   3.0.7
Author   Center Key
🌐
npm
npmjs.com › search
json beautify - npm search
plugin to pretty-print or minify XML, JSON, CSS and SQL files · pretty print · beautify · minify · XML · JSON · CSS · SQL · • 0.40.0 • 14 years ago • 279 dependents • MITpublished version 0.40.0, 14 years ago279 dependents licensed ...
🌐
Research Hubs
researchhubs.com › post › computing › javascript › pretty-print-json.html
Pretty print JSON in Node.js - Research hubs
When you read a JSON file, change the key or value, and write back to the same file, you will lose the JSON formatting. ... 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).
🌐
npm
npmjs.com › package › prettyjson
prettyjson - npm
January 11, 2022 - Decode random strings: if you call the CLI with no arguments, you'll get a prompt where you can past JSON strings and they'll be automatically displayed in a clearer way: It's possible to customize the output through some command line options: # Change colors $ prettyjson --string=red --multiline_string=cyan --keys=blue --dash=yellow --number=green package.json # Do not use colors $ prettyjson --nocolor=1 package.json # Change indentation $ prettyjson --indent=4 package.json # Render arrays elements in a single line $ prettyjson --inline-arrays=1 package.json # Escape conflictive strings $ prettyjson --escape=1 package.json
      » npm install prettyjson
    
Published   Jan 11, 2022
Version   1.2.5
Author   Rafael de Oleza
🌐
npm
npmjs.com › package › pretty-format
pretty-format - npm
1 month ago - That limitation of the original print interface is a reason to use the improved serialize interface, described above. prettyFormat(val, { plugins: [pluginOld], printFunctionName: false, }); /* Object { "onClick": [Function onClick 1], "render": [Function render 0], } */ prettyFormat(val, { printFunctionName: false, }); /* Object { "onClick": [Function], "render": [Function], } */
      » npm install pretty-format
    
Published   Mar 10, 2026
Version   30.3.0
🌐
npm
npmjs.com › package › react-json-pretty
react-json-pretty - npm
A code formatting tool for raw json data. Latest version: 2.2.0, last published: 6 years ago. Start using react-json-pretty in your project by running `npm i react-json-pretty`. There are 124 other projects in the npm registry using react-json-pretty.
      » npm install react-json-pretty
    
Published   Oct 14, 2019
Version   2.2.0
Author   chenckang@gmail.com
🌐
GitHub
github.com › center-key › pretty-print-json
GitHub - center-key/pretty-print-json: 🦋 Pretty-print JSON data into HTML to indent and colorize (with TypeScript declarations)
Or to automatically sense dark mode based on the prefers-color-scheme CSS media feature, use pretty-print-json.prefers.css instead. Install package for node: $ npm install pretty-print-json ·
Starred by 140 users
Forked by 27 users
Languages   TypeScript 61.4% | Shell 38.6% | TypeScript 61.4% | Shell 38.6%
Find elsewhere
🌐
W3Schools
w3schools.io › file › json-nodejs-examples
NodeJS read,write and pretty print JSON file and object example - w3schools
returned pretty print json object before parsing json content using JSON object · prettier is a code formatter that has support for major programming languages. First, Install a prettier npm library · npm install prettier --save-dev · Here is a code for Prettier to format json ·
🌐
npm
npmjs.com › search
pretty-print - npm search
Librarie to format js/json objects into a YAML-style colored output. Especially useful to pretty print logs.
🌐
jsDelivr
jsdelivr.com › package › npm › pretty-print-json
pretty-print-json CDN by jsDelivr - A CDN for npm and GitHub
October 23, 2025 - Pretty-print JSON data into HTML to indent and colorize (written in functional TypeScript) Version 3.0.6 License MIT · Keywords · colorformathtmljavascriptjsonpretty-printpretty-print-jsontypescript · INSTALL · Version: Static · Static · Latest Patch ·
Published   Nov 18, 2018
🌐
Nulldog
nulldog.com › pretty-print-json-in-nodejs
Pretty Print JSON in Node.js
pretty-print-json - npm | Pretty-print JSON data into HTML to indent and colorize (written in functional TypeScript). Latest version: 3.0.2, last published: 20 days ago. Start using pretty-print-json in your project by running npm i pretty-print-json.
🌐
GitHub
github.com › Cerlancism › pretty-color-json-cli
GitHub - Cerlancism/pretty-color-json-cli: A NodeJS command line utility to pretty print JSON string like an object literal to the terminal with color.
A NodeJS command line utility to pretty print JSON string like an object literal to the terminal with color. - Cerlancism/pretty-color-json-cli
Author   Cerlancism
🌐
npm
npmjs.com › package › json-stringify-pretty-compact
json-stringify-pretty-compact - npm
May 14, 2022 - JSON · stringify · pretty · print · pretty-print · compact · indent · format · formatter · npm i json-stringify-pretty-compact · github.com/lydell/json-stringify-pretty-compact · github.com/lydell/json-stringify-pretty-compact#readme · 4,487,206 · 4.0.0 ·
      » npm install json-stringify-pretty-compact
    
Published   May 14, 2022
Version   4.0.0
Author   Simon Lydell
🌐
npm
npmjs.com › search
pretty-json-formatter - npm search
Converts a XML string into a human readable format (pretty print) while respecting the xml:space attribute ... chrisbottin• 3.7.0 • 5 days ago • 329 dependents • MITpublished version 3.7.0, 5 days ago329 dependents licensed under $MIT ...
🌐
Example Code
example-code.com › nodejs › json_pretty_print.asp
Node.js Pretty Print JSON (Formatter, Beautifier)
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • ...
🌐
Coderwall
coderwall.com › p › z3efga › pretty-print-json-from-command-line-with-nodejs
Pretty print JSON from command line with NodeJS (Example)
March 7, 2016 - #!/usr/bin/env node var args = process.argv.splice( /node$/.test(process.argv[0]) ? 2 : 1 ); console.log( JSON.stringify( JSON.parse( require('fs') .readFileSync( args.length > 0 ?
🌐
npm
npmjs.com › search
pretty json - npm search
JSON/CJSON/JSON5 parser, syntax and schema validator and pretty-printer.
🌐
Npm
npm.io › search › keyword:pretty-print
Pretty-print | npm.io
beautifybeautify-jsbeautify-js... values. react-componentpretty-printlogdebug2.1.1 • Published 10 years ago · Function to pretty-print an object with an ability to annotate every value....