{"id":41121,"library":"format-json","title":"format-json","description":"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.","status":"maintenance","version":"1.0.3","language":"javascript","source_language":"en","source_url":"git://github.com/johan/format-json","tags":["javascript"],"install":[{"cmd":"npm install format-json","lang":"bash","label":"npm"},{"cmd":"yarn add format-json","lang":"bash","label":"yarn"},{"cmd":"pnpm add format-json","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is CJS-only; no ES module support. Use require().","wrong":"import formatJson from 'format-json';","symbol":"default export","correct":"const formatJson = require('format-json');"},{"note":"Exported as named property on the module, not as separate file.","wrong":"const { diffy } = require('format-json/diffy');","symbol":"diffy","correct":"const { diffy } = require('format-json');"},{"note":"CJS only; destructure or use module dot notation.","wrong":"import { plain } from 'format-json';","symbol":"plain","correct":"const { plain } = require('format-json');"},{"note":"Also valid via dot notation.","wrong":"const terse = require('format-json').terse;","symbol":"terse","correct":"const { terse } = require('format-json');"}],"quickstart":{"code":"const { diffy, plain, terse } = require('format-json');\nconst data = { test: 'for example', some: [{ nested: 0, things: [] }, {}] };\nconsole.log('Diffy style:');\nconsole.log(diffy(data));\nconsole.log('Plain style:');\nconsole.log(plain(data));\nconsole.log('Terse style:');\nconsole.log(terse(data));","lang":"javascript","description":"Demonstrates the three formatting styles (diffy, plain, terse) on a sample object."},"warnings":[{"fix":"Do not use diffy output with JSON.parse; it is for human-readable diffs only.","message":"diffy style uses comma-first formatting, which may not be valid JSON if parsed by strict parsers. Use only for display or diff purposes.","severity":"gotcha","affected_versions":"*"},{"fix":"Use only for small to moderate sized JSON; for large data, consider streaming JSON formatters.","message":"All functions are synchronous and can block the event loop for large objects.","severity":"gotcha","affected_versions":"*"},{"fix":"Consider alternatives like prettier or json-stringify-pretty-compact for newer projects.","message":"Package is not actively maintained; last release in 2017. No ES module or TypeScript support.","severity":"deprecated","affected_versions":"*"},{"fix":"If you need indentation control, use JSON.stringify with space parameter instead.","message":"No options or customization available; output style is fixed per function.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'comma':21,43 'comma-first':20,42 'compact':35 'control':26 'depend':51 'diff':27,48 'diffi':19 'first':22,44 'format':2,45 'format-json':1 'formatt':6 'javascript':57 'json':3,5 'json.stringify':37 'librari':7 'minim':50 'node.js':9 'offer':15 'optim':46 'plain':28 'pretti':31 'pretty-print':30 'print':32 'provid':39 'readabl':49 'recent':13 'reduc':24 'serial':17 'stabl':11 'standard':29 'stream':55 'style':18 'support':56 'synchron':52 'ters':34 'three':16 'uniqu':41 'unlik':36 'updat':14 'v1.0.3':10 'version':25","created_at":"2026-06-04T18:50:52.740441+00:00","updated_at":"2026-06-04T18:50:52.740441+00:00","problems":[{"fix":"npm install format-json --save","cause":"Package not installed","error":"Error: Cannot find module 'format-json'"},{"fix":"Use `const { diffy } = require('format-json');` and ensure correct spelling.","cause":"Importing incorrectly as ES module or destructuring mismatched name","error":"TypeError: formatJson.diffy is not a function"},{"fix":"Use diffy only for display; for parsing, use plain or terse output.","cause":"Attempting to JSON.parse diffy output, which uses comma-first style (invalid JSON)","error":"SyntaxError: Unexpected token ,"},{"fix":"Use require('format-json').diffy(data) or destructure named exports.","cause":"Calling the module itself as a function (e.g., require('format-json')(data)) instead of using named methods","error":"TypeError: formatJson is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"git://github.com/johan/format-json","github":"git://github.com/johan/format-json","docs":null,"changelog":null,"pypi":null,"npm":"format-json","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}