New:Introducing Socket Scanning for VS Code Marketplace Extensions.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.7
Version published
Maintainers
1
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.

💰 Support DevKits

Love these tools? Support development via Open Collective

  • $5/mo - Supporter (priority support)
  • $9/mo - Pro (early access to new tools)
  • $29 - Lifetime (all current + future Pro features)

💎 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

🔧 More DevKits Tools

Free Tools (82+):

ToolDescription
base64-toolBase64 encode/decode
chmod-calculatorUnix permissions converter
cron-parserCron expression parser
csv-json-converterCSV ↔ JSON converter
diff-checkerText comparison (LCS)

→ Browse All 82+ Free Tools

💎 DevKits Pro — $9 One-Time

Unlock 20+ premium tools with a single payment:

→ Unlock DevKits Pro for $9

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

🚀 Other Products from Us

ProductDescription
InvoicelyFree invoice generator for freelancers
SnapOGFree OG image generator (20+ templates)

License

MIT

Keywords

json

FAQs

Package last updated on 11 Mar 2026

Related posts