User Rating 0.0 ā˜…ā˜…ā˜…ā˜…ā˜…
Total Usage 0 times
Category JSON Tools
Input JSON
Syntax Options
Presets:
Output

      
Is this tool helpful?

Your feedback helps us improve.

ā˜… ā˜… ā˜… ā˜… ā˜…

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.

json converter json formatter json syntax json to js object json5 json quotes trailing commas json indentation

Formulas

The conversion pipeline follows a deterministic three-stage process:

input → JSON.parse(input) → AST → serialize(AST, options) → output

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:

{
quoteKey(k) = k if k matches /^[a-zA-Z_$][a-zA-Z0-9_$]*$/ ∧ unquoted = TRUEquoteKey(k) = Q + k + Q otherwise

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 FeatureStandard JSON (RFC 8259)JSON5JSONCJS Object Literal
Key QuotingRequired (double)OptionalRequired (double)Optional
String QuotesDouble onlySingle or DoubleDouble onlySingle, Double, Backtick
Trailing CommasForbiddenAllowedForbiddenAllowed
CommentsForbidden// line and /* block */// line and /* block */Allowed
Unquoted KeysForbiddenAllowed (identifiers)ForbiddenAllowed (identifiers)
Hexadecimal NumbersForbiddenAllowed (0xFF)ForbiddenAllowed
Infinity / NaNForbiddenAllowedForbiddenAllowed
Multiline StringsForbidden (use \n)Allowed (backslash)ForbiddenTemplate literals
Root Value TypesAny JSON valueAny JSON valueAny JSON valueObject or Array
File Extension.json.json5.jsonc.js / .mjs
MIME Typeapplication/jsonapplication/json5application/jsonapplication/javascript
Parser SupportAll languagesNode.js (json5 pkg)VS Code, TypeScriptJavaScript only
Spec StatusIETF StandardCommunity DraftDe facto (Microsoft)ECMAScript Standard
Use CaseAPIs, data exchangeConfig filesVS Code settingsSource code constants
Max Nesting (typical)Unlimited (parser-dependent)UnlimitedUnlimitedUnlimited
Unicode Escapes\uXXXX\uXXXX\uXXXX\u{XXXXX} extended
Date HandlingString onlyString onlyString onlynew Date() allowed

Frequently Asked Questions

No. RFC 8259 mandates double-quoted strings and forbids trailing commas. Output with single quotes or trailing commas is valid JavaScript but will fail if fed into a strict JSON parser such as JSON.parse. Use these styles only for config files (JSON5) or JS source code.
A key is left unquoted only if it matches the ECMAScript IdentifierName pattern: starts with a letter, underscore, or dollar sign, followed by alphanumeric characters, underscores, or dollar signs. Keys containing spaces, hyphens, dots, or starting with digits are always quoted regardless of the setting. The regex used is /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.
Yes. Sorting is applied recursively at every nesting level. Each object's keys are independently sorted using String.prototype.localeCompare with the "en" locale. Array element order is never modified because arrays are ordered collections by definition.
The native JSON.parse resolves all \uXXXX escapes into their actual Unicode characters. The custom serializer then re-encodes only characters that require escaping in the target quote style (the quote character itself, backslash, and control characters U+0000 through U+001F). All other Unicode characters pass through as literal UTF-8.
The tool processes input in the browser's main thread. For files under 1 MB, conversion is near-instantaneous. Between 1 and 5 MB, expect a brief pause. Above 5 MB, the browser may become unresponsive. For very large datasets, consider using a CLI tool like jq or splitting the file first.
In K&R (Kernighan & Ritchie) style, the opening brace sits on the same line as the key or statement: "key": {. In Allman style, the opening brace drops to its own line, aligned with the parent indentation level. Both produce semantically identical data. The choice is purely aesthetic and should match your project's code style guide.