Format JSON in Zed
How JSON formatting works in the Zed editor, what it changes in a file, how to set it up per language, and when to leave JSON minified or untouched.
Zed can reformat a JSON file in place by re-indenting it and normalizing its whitespace. This review covers what that operation does to the file, how to trigger and configure it, where it falls short, and when you should leave the JSON alone. No product documentation or test results were supplied for this article. The statements below describe general JSON behavior and Zed's settings model as commonly documented. Check them against the Zed version you run.
Is formatting JSON in Zed suitable for your use?
For hand-edited configuration files, fixtures and API samples you need to read or review, formatting in the editor is a good default. Consistent indentation makes nesting visible and keeps version-control diffs focused on real changes. The main tradeoff is that formatting rewrites the file's bytes. That is harmless for JSON consumers but can matter for anything that depends on the exact original text.
- Leave the file unformatted, or format only a copy, when:
- The JSON is signed, hashed or checksummed as raw text. A whitespace change produces a different signature or hash even though the data is identical.
- The file is deliberately minified to reduce payload size, and the minified form is what gets shipped.
- The file is generated by another tool that will overwrite it. Formatting adds diff noise without lasting value.
- A shared repository uses a different indentation convention. Reformatting the whole file creates an unrelated, hard-to-review diff.
What the transformation actually changes
JSON formatting is a stored change to whitespace between tokens: indentation, line breaks and spacing around colons and commas. It is not a visual effect. Soft wrap or a display theme only changes how the file looks on screen, while formatting writes new whitespace to disk when you save. It does not reverse characters or mirror anything, and it does not substitute Unicode lookalike characters. Your keys, values and string contents stay the same characters they were before.
Under the JSON specification, whitespace outside strings has no meaning, so a correct formatter preserves the data. The risk lies in which formatter does the work. Tools that only adjust whitespace leave literals untouched. Tools that parse the document and re-serialize it can introduce changes, depending on the tool and version:
• They may normalize number spellings or lose precision on very large numbers.
• They may collapse duplicate keys.
• They may change escape sequences in strings.
• They may sort keys if that option is enabled.
If exact literals matter, compare a formatted copy against the original before adopting a formatter.
How to run it in Zed
- Open the command palette and run the editor's format command, listed as "editor: format". The palette shows the key binding assigned in your current keymap. Defaults differ by platform and version, so rely on what the palette shows rather than a remembered shortcut.
- To format automatically, enable format on save, either globally or only for JSON.
- If the command does nothing, Zed may not have a JSON formatter or language server active for that file. Check the language shown in the status bar and the configured formatter.
Zed reads its settings from a JSON settings file and allows per-language overrides. A JSON-only configuration typically looks like the example below. Confirm the exact keys and accepted values in the current Zed documentation, because they were not verified for this article.
{
"languages": {
"JSON": {
"format_on_save": "on",
"tab_size": 2,
"formatter": "language_server"
}
}
}
Zed also supports an external command as the formatter. The command receives the buffer contents and returns the formatted text. Using jq looks like the example below. Because jq parses and re-serializes the data, the literal-preservation caveat above applies, and its handling of large numbers has varied between releases.
"formatter": {
"external": {
"command": "jq",
"arguments": ["."]
}
}
Formatting is not validation
A formatter needs syntactically valid input. On broken JSON it usually either refuses to run or produces an error, so a failed format is a hint that the file has a syntax problem. A successful format only shows that the syntax is valid. It says nothing about whether the data has the structure your application expects. For structural checks, rely on schema validation: the JSON language server can apply a schema where one is associated with the file. Treat syntax diagnostics in the editor as a first check, not a guarantee.
Strict JSON versus JSON with comments
Many configuration files, including editor settings, use a relaxed dialect that allows comments and sometimes trailing commas. Strict JSON allows neither. If Zed treats a commented file as strict JSON, you may see errors or a formatter that will not run. If you format a relaxed file and then feed it to a strict parser, the comments will still break that parser. Make sure the language mode matches the file's real dialect. When a strict consumer is involved, remove comments rather than relying on formatting to make the file acceptable.
Will the result stay usable after copying or sharing?
- Copy and paste: formatted JSON is plain text. It pastes as the same characters into any destination that accepts text, and any compliant parser reads it identically to the minified version.
- Destinations that reflow text: chat tools, email clients and web forms may collapse indentation or wrap long lines. Wrap the JSON in a code block where the destination supports one. No destination-specific tests were supplied, so verify the specific tool you share to.
- Search and editing: formatting changes line numbers and line-based diffs, but not the searchable content of keys and values. A search for a key name still finds it.
- Assistive technology: no screen-reader testing was supplied for this article. Indentation is ordinary whitespace and adds no special characters. Whether a screen reader announces nesting depth depends on the reader and its settings.
- When to share a different form: send the minified original when size or exact bytes matter, and the formatted version when people need to read it.
Gaps in this review
No Zed documentation, version details or hands-on test results were supplied. The settings examples, the command name and the description of the JSON language server reflect commonly documented behavior, not verified observations. Default key bindings, formatter options and schema behavior may differ in your installation. Before enabling format on save across a shared project, test the formatter on a representative file and review the diff.