@devkits/json-formatter

Format, validate, and minify JSON. Syntax error detection with position info. Zero-dependency JSON utility for developers.
🧰 DevKits Pro Tools
This package is part of DevKits — 82+ free developer tools. The online JSON Formatter includes schema validation, tree view, and query/filter tools.
→ Format JSON with Tree View
Installation
npm install @devkits/json-formatter
Usage
const {
format,
minify,
isValid,
pretty,
countKeys,
getSizeInfo,
sortKeys,
formatSorted
} = require('@devkits/json-formatter');
const uglyJson = '{"name":"John","age":30,"city":"NYC"}';
const result = format(uglyJson, { indent: 2 });
const min = minify(uglyJson);
isValid('{"valid": true}');
isValid('{invalid}');
pretty({ name: 'John', age: 30 });
const nested = { a: { b: { c: 1 } }, d: [1, 2, 3] };
countKeys(nested);
getSizeInfo(uglyJson);
const unsorted = { z: 1, a: 2, m: 3 };
sortKeys(unsorted);
formatSorted('{"z":1,"a":2}', 2);
API
format(jsonString, options)
Formats JSON with specified indentation (default: 2 spaces).
Returns {success, result?, error?}.
minify(jsonString)
Removes all whitespace from JSON.
Returns {success, result?, error?, saved?}.
isValid(jsonString)
Validates JSON syntax with optional error position.
Returns {valid, error?, position?}.
pretty(obj, indent)
Pretty prints a JavaScript object as JSON string.
countKeys(obj)
Counts all keys in an object recursively.
getSizeInfo(jsonString)
Returns size statistics: original size, minified size, bytes saved, key count.
sortKeys(obj)
Returns new object with keys sorted alphabetically (recursive).
formatSorted(jsonString, indent)
Formats JSON with keys sorted alphabetically.
See Also
Free Online Version: DevKits - JSON Formatter
Other DevKits npm Packages
| @devkits/base64-tool | Base64 encoding/decoding |
| @devkits/csv-json-converter | Convert between CSV and JSON |
| @devkits/markdown-tools | Markdown utilities |
| @devkits/env-editor | .env file utilities |
Browse all 82 tools at DevKits
License
MIT