JSON Formatter
Pretty-print, validate, and sort JSON keys. Real-time validation badge with error line numbers.
How it works
JSON (JavaScript Object Notation) is the dominant data interchange format for web APIs, configuration files, and data storage. When you receive a minified JSON response from an API or need to inspect a config file, pretty-printing makes the structure readable by adding indentation and line breaks.
This formatter parses your JSON input, validates it against the JSON specification, and re-serializes it with your chosen indentation. If you enable "Sort keys," all object keys are alphabetically sorted at every nesting level — this makes JSON output deterministic, which is valuable for diffing, version control, and testing.
The real-time validation badge provides instant feedback as you type. A green "Valid" badge appears when the JSON is well-formed; a red "Invalid" badge shows the exact error message including the position of the syntax error. This happens on every keystroke without submitting anything, so you catch typos — missing commas, unquoted keys, trailing commas — immediately.
Everything runs locally in your browser. JSON payloads often contain sensitive data — API responses with user records, configuration with database credentials, webhook payloads with tokens. This tool ensures that data never leaves your device.
FAQ
Does this formatter fix invalid JSON?
No. The formatter validates strictly against the JSON specification. It will not add missing quotes, fix trailing commas, or convert JavaScript objects (with unquoted keys) to valid JSON. Use a JSON linter or fixer for that.
What indent style should I use?
2 spaces is the most common convention for JSON files in web development (used by npm, ESLint configs, and most APIs). 4 spaces is common in Python ecosystems. Tabs are rare in JSON but some teams prefer them.
Why sort JSON keys?
Sorted keys make JSON output deterministic — the same data always produces the same string. This is essential for comparing JSON in version control diffs, writing snapshot tests, and generating consistent cache keys.
Can I format JSON with comments (JSONC)?
Standard JSON does not support comments. If your input contains // or /* */ comments (common in VS Code settings), the validator will flag it as invalid. Strip comments before formatting.
Is there a size limit?
The formatter runs in your browser. JSON files up to ~50 MB work on most modern devices. For larger payloads, use the Bytario API which supports streaming.