Format, validate, and minify JSON with syntax highlighting and error detection. Sort keys alphabetically and copy the result instantly - browser-only.
Output will appear here
JavaScript Object Notation (JSON), standardized under RFC 8259 and ECMA-404, is the de facto standard data interchange format for modern REST APIs, microservice architectures, and configuration files. Formatting and linting JSON transforms dense, minified payload strings into clearly indented, human-readable representations while detecting syntactic errors.
JSON grammar strictly supports six primitive and composite data structures:
| Data Type | Syntax Example | Technical Rules & Constraints |
|---|---|---|
| String | "username": "alice" | Must be enclosed in double quotes; backslash escapes permitted |
| Number | "count": 42, "ratio": 3.1415 | Decimals permitted; octal, hex (0x), and NaN are strictly invalid |
| Boolean | "active": true, "admin": false | Literal lowercase true or false |
| Null | "metadata": null | Literal lowercase null |
| Object | {"key": "value"} | Unordered collection of key/value pairs; keys must be double-quoted strings |
| Array | [1, 2, 3, "item"] | Ordered list of zero or more values separated by commas |
{"a": 1,}) violate RFC 8259, causing standard parsers to throw errors.{'key': 'val'} is invalid).{ key: "value" }, but JSON requires {"key": "value"}.JavaScript
// Beautify JSON with 2-space indentation
function formatJsonString(rawJson, indentSpaces = 2) {
try {
const parsed = JSON.parse(rawJson);
return { success: true, formatted: JSON.stringify(parsed, null, indentSpaces) };
} catch (err) {
return { success: false, error: err.message };
}
}
// Minify JSON for production payload transfer
function minifyJsonString(rawJson) {
const parsed = JSON.parse(rawJson);
return JSON.stringify(parsed);
}
Python
import json
def prettify_json(raw_json_str: str) -> str:
try:
obj = json.loads(raw_json_str)
return json.dumps(obj, indent=2, sort_keys=True)
except json.JSONDecodeError as exc:
return f"Invalid JSON: {exc}"
This website and utility are provided for general informational, calculation, and educational purposes only. Always verify critical computation outputs prior to professional deployment or financial use. See our Terms of Service and Privacy Policy for full governance details.