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 › @base2 › pretty-print-object
@base2/pretty-print-object - npm
April 28, 2022 - Useful for when you want to get the string representation of an object in a formatted way. It also handles circular references and lets you specify quote type. ... import { prettyPrint } from '@base2/pretty-print-object'; const obj = { foo: ...
      » npm install @base2/pretty-print-object
    
Published   Apr 28, 2022
Version   1.0.2
Author   Chris Baker
Discussions

Pretty-printing nested objects
This is the seminal paper on the topic https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf But as far as I understand it, it gets a lot of power from the laziness of the implementation language. I saw a paper they does it in an eager language but can’t find it at the moment More on reddit.com
🌐 r/ProgrammingLanguages
6
9
September 4, 2024
GitHub - larswaechter/voici.js: A Node.js library for pretty printing your data on the terminal
How is this better than console.table() that’s natively supported ? More on reddit.com
🌐 r/javascript
12
141
February 18, 2023
🌐
Medium
medium.com › trabe › debugging-node-js-with-pp-pretty-print-fe067466bc9e
Debugging Node.js with pp (pretty-print) | by David Barral | Trabe | Medium
June 10, 2021 - Debugging Node.js with pp (pretty-print) Rubyist often use the handy global pp method to do quick console debugging. It’s easy to do the same in Node.js Console-based debugging will never …
🌐
npm
npmjs.com › package › pretty-print-json
pretty-print-json - npm
February 27, 2026 - Pretty-print JSON data into HTML to indent and colorize (written in functional TypeScript). 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 ...
      » npm install pretty-print-json
    
Published   Feb 27, 2026
Version   3.0.7
Author   Center Key
🌐
Minimacode
blog.minimacode.com › pretty-print-json-console-log
Pretty print a JSON object with console.log
January 27, 2022 - Use the JSON.stringify() method to print a JavaScript object on multiple lines for better readability
🌐
npm
npmjs.com › package › js-object-pretty-print
js-object-pretty-print - npm
April 5, 2017 - Serializes a javascript object to a printable string. String is formatted to be used in a pure text environments, like a console log, as an HTML output, or to create a JSON string.
      » npm install js-object-pretty-print
    
Published   Apr 05, 2017
Version   0.3.0
Author   Carlos M. Vadillo
🌐
W3Schools
w3schools.io › file › json-nodejs-examples
NodeJS read,write and pretty print JSON file and object example - w3schools
var jsonData = '{ "active": true, "id": 1, "name": "john" }'; console.log(prettier.format(JSON.stringify(jsonData), { semi: false, parser: "json" }));
Find elsewhere
🌐
npm
npmjs.com › package › pretty-print
pretty-print - npm
July 31, 2018 - rightPadding - extra padding after the object key. Defaults to 2. key - name of the value to use as the list key · value - name of value to use as the list value · var print = require('pretty-print'); var options = { rightPadding: 3, key: 'name', value: 'height' }; print([ { name: 'guy', height: 'short', }, { name: 'girl', height: 'short' } ], options); // outputs: // // guy: short ·
      » npm install pretty-print
    
Published   Jul 31, 2018
Version   2.0.0
Author   Scott Corgan
🌐
Java2s
java2s.com › example › nodejs › object › pretty-print-object.html
Pretty Print object - Node.js Object
function pp(obj) { log(prettyPrint(obj));/*from w ww. ja va 2 s . c om*/ } function prettyPrint(obj) { var toString = Object.prototype.toString, newLine = "\n", space = " ", tab = 4, buffer = "", // Second argument is indent indent = arguments[1] || 0, // For better performance, Cache indentStr for a given indent.
🌐
GitHub
github.com › Chris-Baker › pretty-print-object
GitHub - Chris-Baker/pretty-print-object: Stringify an object/array like JSON.stringify just without all the double-quotes · GitHub
import { prettyPrint } from '@base2/pretty-print-object'; const obj = { foo: 'bar', 'arr': [1, 2, 3], nested: { hello: "world" } }; const pretty = prettyPrint(obj, { indent: ' ', singleQuotes: false, inlineCharacterLimit: 12 }); console.log(pretty); /* { foo: "bar", arr: [1, 2, 3], nested: { hello: "world" } } */
Starred by 5 users
Forked by 3 users
Languages   TypeScript 88.0% | JavaScript 12.0%
🌐
Research Hubs
researchhubs.com › post › computing › javascript › pretty-print-json.html
Pretty print JSON in Node.js - Research hubs
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 › search
pretty-print - npm search
Librarie to format js/json objects into a YAML-style colored output. Especially useful to pretty print logs.
🌐
Coding With Spike!
codingwithspike.wordpress.com › 2016 › 11 › 08 › pretty-printing-javascript-objects
Pretty-printing JavaScript objects with JSON.stringify | Coding With Spike!
November 8, 2016 - We can leverage JSON.stringify() here to make our objects nicely formatted for logging. There is a seldom-used 3rd parameter to stringify() that tells it to print the object with newlines and indentation.
🌐
npm
npmjs.com › package › prettyprint
prettyprint - npm
July 17, 2018 - Function to pretty-print an object with an ability to annotate every value.. Latest version: 1.1.2, last published: 8 years ago. Start using prettyprint in your project by running `npm i prettyprint`. There are 1 other projects in the npm registry ...
      » npm install prettyprint
    
Published   Jul 17, 2018
Version   1.1.2
Author   Gajus Kuizinas
🌐
npm
npmjs.com › package › pretty-print-object
pretty-print-object - npm
December 13, 2015 - Function to pretty-print an object with an ability to annotate every value.. Latest version: 1.1.0, last published: 9 years ago. Start using pretty-print-object in your project by running `npm i pretty-print-object`. There is 1 other project ...
      » npm install pretty-print-object
    
Published   Dec 13, 2015
Version   1.1.0
Author   Gajus Kuizinas
🌐
O'Reilly
oreilly.com › library › view › learning-nodejs-development › 9781788395540 › 77db791c-7729-48fc-bfab-fcd48bd53d80.xhtml
Pretty printing objects - Learning Node.js Development [Book]
Before we continue learning about HTTP and what exactly is inside of error, response, and body, let's take a quick moment to talk about how we can pretty print an object to the screen.
🌐
ReqBin
reqbin.com › code › javascript › ounkkzpp › javascript-pretty-print-json-example
How do I pretty print JSON in JavaScript?
JavaScript has a built-in JSON.stringify(obj, replacer, space) method to convert objects to JSON and pretty-print the generated JSON string.
🌐
Codemzy
codemzy.com › blog › express-pretty-print-json
Pretty print JSON responses with Express - Codemzy's Blog
June 27, 2024 - Here are some ways you can pretty print your JSON responses to the browser with Express in Node.js - either globally or for a single route, using the `space` property of `JSON.stringify()`. To send JSON with Express in Node.js, you can do this: let myObject = { name: "codemzy", likes: [ "javascript", "blogging" ], isWriting: true, }; res.json(myObject); // send as JSON response · res.json() will automatically turn your object into JSON (using JSON.stringify()), and set all the necessary headers to send your data as JSON.