Change JSON Syntax
Convert JSON between syntax styles: single/double quotes, trailing commas, indentation, JS object literals, sorted keys, and more.
About
Standard JSON (RFC 8259) enforces strict rules: double-quoted keys, no trailing commas, no comments. Real-world development demands flexibility. Config files use JSON5 or JSONC. JavaScript source expects unquoted keys and single-quote strings. Pasting RFC-strict JSON into a .js file triggers linter errors. Manually reformatting a 500-line config is error-prone and slow. This tool parses valid JSON via the native JSON.parse engine, then re-serializes it through a custom formatter that applies your chosen syntax rules. It does not use regex-based find-and-replace. It rebuilds the output from the parsed AST, guaranteeing structural correctness regardless of the target style.
Limitations: input must be valid JSON. JSON5 or JS-object input is not accepted because the browser's native parser rejects it. The output in non-standard formats (single quotes, trailing commas) is syntactically valid JavaScript but not valid JSON. If you need to feed the result back into a strict JSON parser, keep double quotes and disable trailing commas. Key sorting uses localeCompare with Unicode-aware ordering, which may differ from ASCII-sort tools.
Formulas
The conversion pipeline follows a deterministic three-stage process:
Where AST is the native JavaScript object tree produced by the parser. The serialize function performs a recursive depth-first traversal. At each node, it applies the following rule set:
Where Q is the selected quote character (", ', or `). Trailing comma injection appends a comma after the last element of every array and object. Key sorting applies Array.prototype.sort with localeCompare before serialization. Indentation depth d at nesting level n equals d = n Ć indentSize.
Reference Data
| Syntax Feature | Standard JSON (RFC 8259) | JSON5 | JSONC | JS Object Literal |
|---|---|---|---|---|
| Key Quoting | Required (double) | Optional | Required (double) | Optional |
| String Quotes | Double only | Single or Double | Double only | Single, Double, Backtick |
| Trailing Commas | Forbidden | Allowed | Forbidden | Allowed |
| Comments | Forbidden | // line and /* block */ | // line and /* block */ | Allowed |
| Unquoted Keys | Forbidden | Allowed (identifiers) | Forbidden | Allowed (identifiers) |
| Hexadecimal Numbers | Forbidden | Allowed (0xFF) | Forbidden | Allowed |
| Infinity / NaN | Forbidden | Allowed | Forbidden | Allowed |
| Multiline Strings | Forbidden (use \n) | Allowed (backslash) | Forbidden | Template literals |
| Root Value Types | Any JSON value | Any JSON value | Any JSON value | Object or Array |
| File Extension | .json | .json5 | .jsonc | .js / .mjs |
| MIME Type | application/json | application/json5 | application/json | application/javascript |
| Parser Support | All languages | Node.js (json5 pkg) | VS Code, TypeScript | JavaScript only |
| Spec Status | IETF Standard | Community Draft | De facto (Microsoft) | ECMAScript Standard |
| Use Case | APIs, data exchange | Config files | VS Code settings | Source code constants |
| Max Nesting (typical) | Unlimited (parser-dependent) | Unlimited | Unlimited | Unlimited |
| Unicode Escapes | \uXXXX | \uXXXX | \uXXXX | \u{XXXXX} extended |
| Date Handling | String only | String only | String only | new Date() allowed |