JSPM

jsonfmt-dev

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q53938F
  • License MIT

JSON formatter, validator, differ & stats — zero dependencies, colorized CLI. jsonfmt.dev

Package Exports

  • jsonfmt-dev
  • jsonfmt-dev/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jsonfmt-dev) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@jsonfmt/cli

Format, validate, diff, and inspect JSON from your terminal.

Zero dependencies. Colorized output. Runs anywhere Node.js runs.

npm version license node downloads


Install

npm install -g @jsonfmt/cli

Or run instantly without installing:

npx @jsonfmt/cli '{"hello":"world"}'

Quick Start

# Format a file
jsonfmt data.json

# Pipe from stdin
echo '{"name":"Alice","age":30}' | jsonfmt

# Validate
jsonfmt --validate data.json

# Diff two files
jsonfmt --diff a.json b.json

# Get stats
jsonfmt --stats data.json

Output Example

$ echo '{"name":"Alice","age":30,"roles":["admin","user"],"active":true}' | jsonfmt

{
  "name": "Alice",
  "age": 30,
  "roles": [
    "admin",
    "user"
  ],
  "active": true
}
$ jsonfmt --stats data.json

  keys       3
  strings    1
  numbers    1
  booleans   1
  arrays     1
  objects    1
  depth      2
  bytes      65
$ jsonfmt --diff a.json b.json

  ~ age: 28 → 29
  + role: "admin"
  - email: "old@test.com"

All Options

Flag Description Example
(no flag) Pretty-print with colors jsonfmt data.json
--minify Compact single-line output jsonfmt --minify data.json
--sort-keys Sort object keys A-Z jsonfmt --sort-keys data.json
--validate Check validity (exit 0/1) jsonfmt --validate data.json
--stats Count keys, types, depth, bytes jsonfmt --stats data.json
--diff <file> Compare two JSON files jsonfmt --diff a.json b.json
--get <path> Extract value by dot-path jsonfmt --get "users[0].name" data.json
--indent <n|tab> Set indentation (default: 2) jsonfmt --indent 4 data.json
--max-depth <n> Truncate nested output jsonfmt --max-depth 3 data.json
--max-array <n> Truncate long arrays jsonfmt --max-array 5 data.json
--no-color Disable ANSI colors jsonfmt --no-color data.json > out.txt
--help Show help jsonfmt --help

Use Cases

CI/CD pipelines — validate JSON configs before deploy:

jsonfmt --validate config.json || exit 1

API debugging — format curl responses:

curl -s https://api.example.com/users | jsonfmt

Extract values — pull fields from JSON files:

jsonfmt --get "database.host" config.json

Compare configs — diff staging vs production:

jsonfmt --diff staging.json production.json

Minify for storage — shrink JSON payloads:

jsonfmt --minify large.json > small.json

How It Works

Custom Lexer -> Parser -> AST pipeline (same engine as jsonfmt.dev):

Input string
  → Lexer (tokenize: strings, numbers, braces, colons)
  → Parser (build AST: objects, arrays, values)
  → Formatter (colorize + indent)
  → Terminal output
  • Better error messages than JSON.parse — shows exact line and column
  • Handles all JSON edge cases (unicode escapes, nested depth, large files)
  • Zero dependencies — single 25KB file, no node_modules

Ecosystem

Product What Link
Web App Full JSON toolkit (33 converters, 8 tabs, AI Helper) jsonfmt.dev
API 63 REST endpoints for JSON processing api.jsonfmt.dev/docs
CLI This package npm i -g @jsonfmt/cli
Chrome Extension Auto-format JSON in browser tabs Chrome Web Store
Bookmarklet One-click format on any page jsonfmt.dev/bookmarklet

Why Not Just Use jq?

jsonfmt jq
Install npm i -g @jsonfmt/cli Separate binary, varies by OS
Syntax Familiar flags (--get, --diff) Custom query language to learn
Colors Built-in, automatic Requires --color-output
Diff --diff a.json b.json Not built-in
Validate --validate with exit codes jq . > /dev/null (workaround)
Stats --stats (types, depth, bytes) Not built-in
Deps Zero C binary

Use jsonfmt for formatting, validating, and inspecting. Use jq for complex data transformations.


License

MIT


jsonfmt.dev — Format, validate, convert, diff, repair, and query JSON.