Registry / devops / format-json

format-json

JSON →
library1.0.3jsnpmunverified

A JSON formatter library for Node.js (v1.0.3, stable, no recent updates) offering three serialization styles: 'diffy' (comma-first for reduced version control diffs), 'plain' (standard pretty-print), and 'terse' (compact). Unlike JSON.stringify, it provides a unique comma-first format optimized for diff readability. Minimal dependencies; synchronous only; no streaming support.

npm install format-json
INSTALL
IMPORT
SIG · FORMAT-JSON
F
format-json
devopsjavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
const formatJson = require('format-json');
import formatJson from 'format-json';
Package is CJS-only; no ES module support. Use require().
diffy
const { diffy } = require('format-json');
const { diffy } = require('format-json/diffy');
Exported as named property on the module, not as separate file.
plain
const { plain } = require('format-json');
import { plain } from 'format-json';
CJS only; destructure or use module dot notation.
terse
const { terse } = require('format-json');
const terse = require('format-json').terse;
Also valid via dot notation.

Demonstrates the three formatting styles (diffy, plain, terse) on a sample object.

const { diffy, plain, terse } = require('format-json'); const data = { test: 'for example', some: [{ nested: 0, things: [] }, {}] }; console.log('Diffy style:'); console.log(diffy(data)); console.log('Plain style:'); console.log(plain(data)); console.log('Terse style:'); console.log(terse(data));
Debug
Known issues
gotchadiffy style uses comma-first formatting, which may not be valid JSON if parsed by strict parsers. Use only for display or diff purposes.
fix
Do not use diffy output with JSON.parse; it is for human-readable diffs only.
affects: *
gotchaAll functions are synchronous and can block the event loop for large objects.
fix
Use only for small to moderate sized JSON; for large data, consider streaming JSON formatters.
affects: *
deprecatedPackage is not actively maintained; last release in 2017. No ES module or TypeScript support.
fix
Consider alternatives like prettier or json-stringify-pretty-compact for newer projects.
affects: *
gotchaNo options or customization available; output style is fixed per function.
fix
If you need indentation control, use JSON.stringify with space parameter instead.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'format-json'
Package not installed
fix
npm install format-json --save
TypeError: formatJson.diffy is not a function
Importing incorrectly as ES module or destructuring mismatched name
fix
Use `const { diffy } = require('format-json');` and ensure correct spelling.
SyntaxError: Unexpected token ,
Attempting to JSON.parse diffy output, which uses comma-first style (invalid JSON)
fix
Use diffy only for display; for parsing, use plain or terse output.
TypeError: formatJson is not a function
Calling the module itself as a function (e.g., require('format-json')(data)) instead of using named methods
fix
Use require('format-json').diffy(data) or destructure named exports.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
format-json — npm install format-json · libregistry