Skip to main content

/json-format - Format and Validate JSON

Format, validate, and manipulate JSON data with syntax highlighting.

System Prompt

EXECUTION DIRECTIVE: When /json-format is invoked, IMMEDIATELY process the JSON.

Usage

/json-format '{"a":1,"b":2}'           # Pretty print
/json-format -c '{"a": 1}' # Compact (minify)
/json-format -v '{"a":1}' # Validate only
/json-format -f config.json # Format file
/json-format -q '.key' '{"key":"val"}' # Query with jq
/json-format --sort '{"b":1,"a":2}' # Sort keys

Execution

~/.coditect/scripts/json-format.sh '{"a":1}'
~/.coditect/scripts/json-format.sh -c '{"a": 1}'
~/.coditect/scripts/json-format.sh -v '{"a":1}'
~/.coditect/scripts/json-format.sh -f config.json

Operations

FlagOperationDescription
(none)Pretty printFormat with indentation
-cCompactRemove whitespace
-vValidateCheck syntax only
-f FILEFileProcess file
-q EXPRQueryjq expression
--sortSort keysAlphabetical order
--depth NDepthLimit nesting display

Output Format

Pretty Print

{
"name": "coditect",
"version": "2.8.0",
"features": [
"agents",
"skills",
"commands"
]
}

Validation Result

======================================================================
JSON Validation
======================================================================

Status: VALID
Size: 156 bytes
Keys: 3 (top-level)
Depth: 2 levels

======================================================================

Validation Error

======================================================================
JSON Validation
======================================================================

Status: INVALID
Error: Expecting ',' delimiter: line 3 column 5

Line 3: "key" "value"
^ Missing comma

======================================================================

Examples

Pretty Print

$ /json-format '{"name":"test","items":[1,2,3]}'
{
"name": "test",
"items": [
1,
2,
3
]
}

Minify

$ /json-format -c '{
"name": "test",
"value": 123
}'
{"name":"test","value":123}

Query with jq

$ /json-format -q '.items[0]' '{"items":["a","b","c"]}'
"a"

Implementation

#!/bin/bash
case "$1" in
-c) python3 -c "import json,sys; print(json.dumps(json.loads(sys.argv[1])))" "$2" ;;
-v) python3 -c "import json,sys; json.loads(sys.argv[1]); print('Valid JSON')" "$2" ;;
*) python3 -c "import json,sys; print(json.dumps(json.loads(sys.argv[1]), indent=2))" "$1" ;;
esac
CommandPurpose
/encodeEncode/decode
/config-validateValidate configs

Version: 1.0.0 Created: 2026-01-15 Author: CODITECT Team