Format and validate JSON — pretty-print with configurable indentation or minify to a single line.
JSON.parse(input) conceptually — parse the string strictly following JSON spec.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.JSON.stringify(parsed) semantics.indent: 2 (default) | 4 — number of spaces per indent levelaction: format (default) | minify | validatesort-keys: false (default) | true — sort object keys alphabeticallyFormat (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
}
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).共 1 个版本