Registry / devops / simple-json-formatter

simple-json-formatter

JSON →
library1.0.2jsnpmunverified

A minimal library to format JSON strings with custom indentation. Current stable version 1.0.2, no recent updates. Provides a single `format` function that parses JSON and re-serializes with configurable indent (defaults to spaces). Simpler than alternatives like `json-stringify-pretty-compact`; no CLI or advanced options. Suitable for Node.js and browser, but not actively maintained.

npm install simple-json-formatter
INSTALL
IMPORT
SIG · SIMPLE-JSON-FORMAT
S
simple-json-formatter
devopsjavascriptv1.0.2
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.

format
import { format } from 'simple-json-formatter'
const JSONFormatter = require('simple-json-formatter'); JSONFormatter.format(...)
The package has no default export; use named import. The README shows require destructuring but 'JSONFormatter' is not a default export.
format
const { format } = require('simple-json-formatter')
const JSONFormatter = require('simple-json-formatter').default
CommonJS destructuring works. The module exports an object with 'format' function.
format
const format = require('simple-json-formatter').format
Alternative CommonJS import without destructuring.

Demonstrates formatting a JSON string with 2-space indent using the format function.

import { format } from 'simple-json-formatter'; const obj = { name: 'Alice', scores: [95, 87], meta: { active: true } }; const jsonString = JSON.stringify(obj); console.log('Raw:', jsonString); // Output: {"name":"Alice","scores":[95,87],"meta":{"active":true}} const formatted = format(jsonString, ' '); console.log('Formatted:', formatted); /* Output: { "name": "Alice", "scores": [ 95, 87 ], "meta": { "active": true } } */
Debug
Known issues
gotchaThe input must be a valid JSON string; otherwise format throws an error.
fix
Wrap in try-catch or validate JSON via JSON.parse first.
affects: >=1.0.0
gotchaThe default indent if not provided is a space character (" "), not tab or two spaces.
fix
Always pass explicit indent string (e.g., '  ' or '\t').
affects: >=1.0.0
deprecatedPackage not updated since 2018; no TypeScript typings included.
fix
Use native JSON.stringify(obj, null, indent) or more popular alternatives like prettier.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: JSONFormatter.format is not a function
Importing using default import or wrong variable name.
fix
Use named import: import { format } from 'simple-json-formatter'
SyntaxError: Unexpected token ... in JSON at position 0
Passing non-string or invalid JSON to format().
fix
Ensure first argument is a stringified JSON, e.g., JSON.stringify(obj)
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

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