JSON Formatter

Format (pretty-print), minify, or validate JSON data.

Commands

# Format (pretty-print)
devv json format '{"a":1,"b":[2,3]}'
devv json format '{"z":1,"a":2}' --sort-keys
devv json format '{"a":1}' --indent 4

# Minify
devv json minify '{ "a": 1, "b": 2 }'

# Validate
devv json validate '{"valid": true}'
devv json validate '{broken'

Examples

# Format a file
cat package.json | devv json format --sort-keys

# Minify for storage
cat data.json | devv json minify

# Validate API response
curl -s https://api.example.com/data | devv json validate

Output

$ devv json format '{"name":"devv","version":1}'
{
  "name": "devv",
  "version": 1
}

$ devv json validate '{"valid": true}'
 Valid JSON

$ devv json validate '{broken'
 Unexpected token b in JSON at position 1

Pipeline Usage

Pipeline ID Description
json-formatter Format/pretty-print JSON
json-validator Validate JSON (passthrough)
# In a pipeline
devv pipe exec "json-formatter | base64-encode" '{"key":"value"}'
devv pipe exec "base64-decode | json-formatter" "eyJrZXkiOiJ2YWx1ZSJ9"
devv pipe exec "json-validator | json-formatter --sort-keys" '{"b":2,"a":1}'

Options in pipelines

json-formatter indent=4
json-formatter --sort-keys

Behavior

  • json-formatter — transforms input (formatted output passes to next step)
  • json-validator — passthrough (original input forwarded to next step, validation result shown)

Options

Option Description Default
--sort-keys Sort object keys alphabetically false
--indent <n> Indentation spaces 2
Was this page helpful?