JSON Formatter

Sorting rebuilds the output and removes comments.

Format, validate, view, convert, and minify JSON or JSON5 in your browser. Select the accepted input syntax and desired output syntax separately, choose tabs or 2 to 4 spaces, and optionally sort object keys recursively. Syntax errors are shown in the output editor.

Choose JSON or JSON5 independently for the input and output. JSON5-to-JSON5 formatting preserves comments, while conversion, key sorting, and minification serialize the parsed data into the selected output syntax.

  • Unquoted field names are allowed (e.g., {name: "Alice"} instead of {"name": "Alice"});
  • Single quotes can be used for strings (e.g., {'name': 'Bob'});
  • Trailing commas are permitted (e.g., {"a": 1, "b": 2,});

Use JSON output for APIs and systems that require standard JSON. Use JSON5 output for developer-maintained configuration where comments, NaN, Infinity, and other JSON5 values need to remain valid.

Code formatter FAQ

How do I format code on this page?

Paste code into the left editor or load a file, choose the options you need, and select Format. Review the result on the right, then copy or save it.

Why might the formatter report an error?

The input must match the selected language or syntax. Check incomplete statements, unmatched brackets or quotes, and a dialect or mode that does not match the input, then format again.

How does a code formatter work?

A code formatter reads language-aware tokens and nested structures, then rewrites indentation, spacing, and line breaks according to a consistent rule set. It does not compile or run the program, so formatting is not a correctness or security check.

Which settings are recommended for this language?

Use 2 spaces and standard JSON for APIs and configuration files. Select JSON5 only when comments or trailing commas are intentional, and sort keys only when key order is not meaningful to readers. Choose JSON or JSON5 independently for input and output, sort object keys, set indentation, open the structured view, or create minified output.