New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

devkits-json-formatter

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

devkits-json-formatter

Format, validate, and minify JSON. Syntax error detection with position info. Zero-dependency JSON utility for developers.

Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
11
450%
Maintainers
1
Weekly downloads
 
Created
Source

@devkits/json-formatter

Part of DevKits DevKits Pro

Format, validate, and minify JSON. Syntax error detection with position info. Zero-dependency JSON utility for developers.

💎 Upgrade to DevKits Pro

Get access to 20+ premium tools including SQL to Code, Data Faker, JWT Generator, and more — all for $9 one-time.

→ Unlock DevKits Pro

💡 Pay with Crypto: BTC, ETH, USDT (TRC-20), SOL accepted. View crypto addresses

🧰 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"}';

// Format JSON with indentation
const result = format(uglyJson, { indent: 2 });
// {
//   success: true,
//   result: '{\n  "name": "John",\n  "age": 30,\n  "city": "NYC"\n}'
// }

// Minify JSON
const min = minify(uglyJson);
// { success: true, result: '{"name":"John",...}', saved: 15 }

// Validate JSON
isValid('{"valid": true}');
// { valid: true }

isValid('{invalid}');
// { valid: false, error: 'Unexpected token...', position: {line: 1, column: 2} }

// Pretty print an object
pretty({ name: 'John', age: 30 });
// '{\n  "name": "John",\n  "age": 30\n}'

// Count keys recursively
const nested = { a: { b: { c: 1 } }, d: [1, 2, 3] };
countKeys(nested);
// 5

// Get size info
getSizeInfo(uglyJson);
// { original: 36, minified: 36, saved: 0, keys: 3 }

// Sort keys alphabetically
const unsorted = { z: 1, a: 2, m: 3 };
sortKeys(unsorted);
// { a: 2, m: 3, z: 1 }

// Format with sorted keys
formatSorted('{"z":1,"a":2}', 2);
// { success: true, result: '{\n  "a": 2,\n  "z": 1\n}' }

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

  • DevKits — 82 free developer tools
  • Invoicely — Free invoice generator
  • SnapOG — Free OG image generator

License

MIT

Keywords

json

FAQs

Package last updated on 09 Mar 2026

Related posts