prettyjson is a Node.js package designed to format JSON data into a human-readable, colored YAML-style output, primarily for command-line interface (CLI) applications. It offers both a programmatic API for Node.js scripts and a direct CLI tool for processing JSON files, `stdin`, or interactive input. The current stable version is 1.2.5. Release cadence appears sporadic, with the last update over a year ago, but still maintained with dependency fixes. Its key differentiator lies in its focus on visually appealing, colored output directly in the terminal, making debugging and data inspection easier compared to raw JSON. It allows extensive customization of colors and formatting options, including indentation and inline arrays. It depends on the `colors` library for terminal output styling.
npm install prettyjsonVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically use `prettyjson` to render a complex JavaScript object into a colored, YAML-style string, customizing colors and indentation.
Migrate all configuration from environment variables to CLI arguments or options passed directly to the `render` method.
Ensure `colors` is pinned to a safe version (`1.4.0` or later stable versions if `prettyjson` updates) in your project's `package-lock.json` or `yarn.lock` files, and regularly audit your dependency tree for security vulnerabilities.
For CommonJS, use `const prettyjson = require('prettyjson');`. For ESM projects, consider using dynamic `import('prettyjson')` or a build tool to handle CJS module imports.Ensure `const prettyjson = require('prettyjson');` is at the top of your file and `prettyjson` is accessible in the current scope.Run `npm install prettyjson` or `yarn add prettyjson` in your project directory.
Verify the correct CLI option name. For example, the `noalign` option was introduced as `--noalign` in v1.2.0, but other options like `--nocolor` or `--inline-arrays` have specific spellings. Refer to the documentation for supported arguments.