Json Format
by @ohernandez-dev-blossom
Format, prettify, minify, or validate JSON. Use when the user asks to format JSON, prettify JSON, beautify JSON, minify JSON, compress JSON, validate JSON, f...
clawhub install json-formatπ About This Skill
name: json-format description: Format, prettify, minify, or validate JSON. Use when the user asks to format JSON, prettify JSON, beautify JSON, minify JSON, compress JSON, validate JSON, fix JSON indentation, or make JSON readable.
JSON Formatter
Format and validate JSON β pretty-print with configurable indentation or minify to a single line.
Input
Output
Instructions
1. Receive the raw JSON string from the user.
2. Determine the requested action (default: format).
3. Attempt to parse the JSON:
- Call JSON.parse(input) conceptually β parse the string strictly following JSON spec.
- If parsing fails, report the error with as much detail as possible (e.g., "Unexpected token at position 42", "Missing closing bracket").
4. For format action:
- Serialize the parsed value back to a string with the requested indent size (default: 2 spaces).
- Use JSON.stringify(parsed, null, indentSize) semantics: keys are sorted by insertion order (not alphabetically), arrays and objects are expanded across multiple lines, strings are double-quoted.
5. For minify action:
- Serialize with no indentation or extra whitespace: JSON.stringify(parsed) semantics.
6. For validate action:
- If parsing succeeded, report "Valid JSON" along with type and top-level key count if it is an object.
- If parsing failed, report the error message.
7. If sort-keys option is requested, sort all object keys alphabetically at every nesting level before serializing.
8. Output the result.
Options
indent: 2 (default) | 4 β number of spaces per indent levelaction: format (default) | minify | validatesort-keys: false (default) | true β sort object keys alphabeticallyExamples
Format (default, 2-space indent)
Input:
{"name":"Alice","age":30,"hobbies":["reading","coding"]}
Output:
{
"name": "Alice",
"age": 30,
"hobbies": [
"reading",
"coding"
]
}
Minify
Input:
{
"name": "Alice",
"age": 30
}
Output:
{"name":"Alice","age":30}
Validate β invalid JSON
Input:
{name: 'Alice', age: 30}
Output:
Invalid JSON: Unexpected token 'n' at position 1. Keys must be double-quoted strings and string values must use double quotes, not single quotes.
Format with 4-space indent and sort-keys
Input:
{"z":3,"a":1,"m":2}
Output:
{
"a": 1,
"m": 2,
"z": 3
}
Error Handling
JSON.parse fails, report the error message and the approximate position or line number if determinable. Do not attempt to silently fix the JSON β report the exact parse error. (If the user wants repair, suggest using the json-repair skill.)42 or "hello"), format it as-is (a primitive is valid JSON).π‘ Examples
Format (default, 2-space indent)
Input:
{"name":"Alice","age":30,"hobbies":["reading","coding"]}
Output:
{
"name": "Alice",
"age": 30,
"hobbies": [
"reading",
"coding"
]
}
Minify
Input:
{
"name": "Alice",
"age": 30
}
Output:
{"name":"Alice","age":30}
Validate β invalid JSON
Input:
{name: 'Alice', age: 30}
Output:
Invalid JSON: Unexpected token 'n' at position 1. Keys must be double-quoted strings and string values must use double quotes, not single quotes.
Format with 4-space indent and sort-keys
Input:
{"z":3,"a":1,"m":2}
Output:
{
"a": 1,
"m": 2,
"z": 3
}
βοΈ Configuration
indent: 2 (default) | 4 β number of spaces per indent levelaction: format (default) | minify | validatesort-keys: false (default) | true β sort object keys alphabetically