Format JSON in Sublime Text
How to format JSON in Sublime Text, what pretty-printing changes in your file, and when formatting can alter data or cause problems after copying.
Formatting JSON in Sublime Text usually means pretty-printing: taking compact or messy JSON and adding line breaks and indentation so its structure is easy to read. This review covers how to do that, what the operation changes in your file, and the cases where the result is not a faithful or practical copy of the original.
Short answer: is it suitable for your use?
For reading, reviewing and hand-editing JSON, formatting in Sublime Text is generally a good fit. JSON treats whitespace between tokens as insignificant, so a correct formatter produces data that a parser reads the same way as the original. The main benefit is that nesting, arrays and missing or extra brackets become visible at a glance.
The main tradeoff is that most formatters parse the JSON and then write it out again rather than simply adding spaces. Re-serialization can change details that some workflows care about, such as key order, number spelling, Unicode escapes or duplicate keys. If you need a byte-for-byte copy, for example for a signature, checksum, cache key or a fixture compared as raw text, keep the original unformatted text and format a separate copy only for reading.
Compact (minified) JSON is preferable when size matters, such as for network payloads or single-line log entries. Formatted JSON is better for config files, code review and debugging.
How to format JSON in Sublime Text
Sublime Text does not provide a dedicated JSON pretty-print command out of the box. Its built-in Reindent command, under Edit > Line, only adjusts indentation on existing lines. It does not split a single-line JSON blob into a readable structure. In practice, there are two common approaches: install a package, or pipe the text through an external formatter.
Option 1: Install a JSON formatting package
- 1. Open the Command Palette (Ctrl+Shift+P on Windows and Linux, Cmd+Shift+P on macOS).
- 2. If Package Control is not installed, run the command "Install Package Control".
- 3. Run "Package Control: Install Package" and search for a JSON formatter. Pretty JSON is a widely used option.
- 4. Open your JSON file, or set the syntax with View > Syntax > JSON so highlighting matches the content.
- 5. Open the Command Palette again and run the package's format or prettify command.
Packages often add keyboard shortcuts and settings for indent width, key sorting and validation. Shortcuts and option names can change between versions, so check the package's own documentation instead of relying on a remembered key combination.
Option 2: Use an external formatter
If you prefer not to install a package, you can format JSON with a command-line tool and paste the result back, or run the tool on the file directly. Two common tools are Python's built-in json.tool module and jq. Both parse the input, so invalid JSON produces an error instead of formatted output, which also makes them a quick way to validate.
python3 -m json.tool input.json > formatted.json
jq . input.json > formatted.json
Write the result to a new file, as above, rather than redirecting output onto the file you are reading. In many shells, redirecting onto the input file empties it before the tool reads it.
What formatting actually changes
Formatting changes the stored text, not just how it looks. Syntax highlighting and font settings in Sublime Text are only visual and leave the file untouched. Pretty-printing, by contrast, inserts real newline and space or tab characters into the file. Once you save, those characters are part of the file and travel with it when copied or committed.
Here is an illustrative example. The compact input and the formatted output below describe the same data. Only whitespace between tokens differs, and the space inside the string value is kept as is.
{"name":"Ada Lovelace","tags":["math","computing"],"active":true}
{
"name": "Ada Lovelace",
"tags": [
"math",
"computing"
],
"active": true
}
Because most formatters parse and re-serialize the data, the following can differ from the original, depending on the tool and its settings:
- Key order: some formatters can sort keys alphabetically. This is harmless to most parsers but noisy in diffs.
- Numbers: a parser may rewrite a number's spelling, such as an exponent form, or lose precision on very large integers if it reads numbers as floating point.
- Unicode: non-ASCII characters may be converted to \u escape sequences, or escapes may be expanded. Python's json.tool escapes non-ASCII by default unless you pass --no-ensure-ascii.
- Duplicate keys: JSON parsers commonly keep only one value for a repeated key, so a duplicate can silently disappear.
- Comments and trailing commas: these are not valid in standard JSON. Sublime Text's own settings files allow them, but a strict formatter may reject such a file or strip the extras.
If any of these matter, compare the original and formatted versions with a JSON-aware tool or a careful diff before replacing the original. Do not assume a particular package avoids them. Check its settings and documentation, because the evidence for this review does not confirm the exact behavior of any specific package version.
Will the result stay readable and usable after copying or sharing?
Formatted JSON is ordinary plain text, so it does not depend on special fonts or characters. Copying it from Sublime Text keeps the characters you see. Whether the indentation survives depends on the destination. Code editors and properly fenced code blocks generally keep whitespace, while some chat tools, email clients or rich-text fields may reflow lines, collapse spaces or turn quotes into curly quotes. Curly quotes break JSON. This review has no tested results for specific destinations, so check the pasted output wherever you share it.
Tabs versus spaces also affects how the result looks elsewhere. Tabs can render at different widths in other tools, so spaces give more consistent results when sharing.
For accessibility, line breaks and indentation help sighted readers follow the nesting. How a screen reader announces indentation depends on the reader and its settings, and no scoped test for this was available. When sharing data with someone using assistive technology, a short plain-language summary of the key fields, or the compact form plus a description, may serve them better than deeply indented output.
For search and editing, formatting usually helps. One value per line makes find-and-replace, line-based diffs and code review easier to follow. The exception is grepping logs or tools that expect one JSON object per line, such as JSON Lines files. Pretty-printing breaks that one-record-per-line structure, so keep those files compact.
Which approach fits which need
| Need | Recommended approach | Caveat |
| Read or debug a JSON file | Formatting package in Sublime Text | Check whether key sorting is enabled |
| Validate and format without extra packages | json.tool or jq from the command line | Writes re-serialized output, not the original bytes |
| Preserve exact bytes | Keep the original; format a separate copy | Never overwrite the source |
| Send over a network or store as one-line logs | Keep compact or minified JSON | Harder to read by eye |
| Edit Sublime Text settings with comments | Edit by hand; avoid strict JSON formatters | Comments and trailing commas are not standard JSON |
Gaps in the available evidence
No version-specific test results, package benchmarks or destination-by-destination copy tests were available for this review. Statements about JSON whitespace and parser behavior reflect the JSON standard and documented behavior of common tools. Exact menu names, shortcuts and package options should be confirmed against your installed Sublime Text and package versions.