Sublime Text 沒有內建的一鍵 JSON 格式化工具,因此在 Sublime 中格式化 JSON 代表要安裝像是 Pretty JSON 或 JSON Reindent 這類外掛——並接受伴隨編輯器擴充功能、快捷鍵衝突,以及靜默接受無效輸入而來的權衡取捨。Sublime Text 內建有 JSON 語法突顯與一套能在明顯問題出現時標記出來的語法檢查器,但當你貼上經壓縮的 API 回應的那一刻起,你就得靠自己去找外掛、設定快捷鍵綁定,並相信格式化步驟同時也會驗證結構是否正確。Pretty JSON(在 Windows 與 Linux 上預設為 Ctrl+Alt+J,在 macOS 上為 Cmd+Alt+J)會重新縮排、驗證並摺疊;JSON Reindent 只重新縮排而不驗證,速度較快但會默默保留損壞的 JSON;HTML-CSS-JS Prettify 包裝了 js-beautify 引擎,當你將其 json 旗標切為 true 時就能處理 JSON。這些外掛在完整設定好的 Sublime 安裝中都能運作,但它們全都假設輸入已是有效的 UTF-8 JSON、把錯誤藏在籠統的「parse failed」訊息背後,並且一旦有註解、結尾逗號或單引號字串滲入就會崩解。這段落差正好是瀏覽器端工具能發揮所長之處——它結合了格式化、壓縮,以及行列錯誤回報,因此成為更安全的備援方案。

how to format json in sublime
How to Format JSON in Sublime Text: Plugins and Beyond

What Sublime Text Actually Gives You for JSON

Sublime Text 開箱即用就能辨識 .json 副檔名並套用 JSON 文法,藉此提供語法突顯以及在儲存時執行基本的語法檢查。沒有任何選單指令、預設快捷鍵綁定或設定檔項目能美化 JSON 文件。最接近的內建功能是位於 Edit → Line → Reindent 下的 Reindent 指令,它會依目前檔案的 tab 寬度調整縮排,但不會執行任何剖析——對於字串、註解和損壞的結構,它會一視同仁地重新縮排。

如果你開啟的檔案 Sublime 並未辨識為 JSON(例如貼到新分頁的剪貼簿內容,經常會落入「Plain Text」),格式化外掛指令將拒絕執行。解決方法是點選右下角狀態列的語言標籤,並明確切換為 JSON。這是第一個陷阱:人們貼上內容、按下快捷鍵、看到什麼事都沒發生,便以為外掛壞了,但事實上是語法模式不對。

Sublime JSON Plugins Worth Installing

Three plugins cover almost every Sublime JSON workflow. Pick based on whether you also want validation.

PluginValidates JSON?Default shortcutBest for
Pretty JSONYes (raises a dialog on parse error)Ctrl+Alt+J / Cmd+Alt+JEveryday reformatting of files you trust
JSON ReindentNo — only re-indentsOften unbound or Ctrl+Shift+JSpeed on already-validated payloads
HTML-CSS-JS PrettifyYes (via js-beautify)Ctrl+Shift+HProjects that also touch JS, CSS, and HTML

Install any of them through Preferences → Package Control → Install Package, then search by name. Pretty JSON is the most popular pick because it combines beautification, validation, and folding in one shortcut. JSON Reindent is the lightweight alternative when you have already validated the payload with another tool — for example, after running python -m json.tool yourfile.json on the command line. HTML-CSS-JS Prettify needs its json setting flipped to true in the plugin preferences before it will touch JSON files; otherwise it silently skips them.

Limits and Pitfalls of Plugin-Based Formatting

Plugin-based formatting has three recurring failure modes that are easy to miss until they bite.

  • Shortcut conflicts. Pretty JSON's default Ctrl+Alt+J overlaps with a built-in Sublime binding on some platforms and with other plugins. When the shortcut stops working, the fix is to open Preferences → Key Bindings and remap it to something like Ctrl+Alt+F or Ctrl+Shift+I.
  • Silent acceptance of bad JSON. JSON Reindent does not parse — it only adjusts whitespace. If you feed it a string with a trailing comma, it returns text that looks formatted but is still invalid. Pretty JSON pops a dialog on parse errors, which is more helpful, but the dialog text is short and lacks line or column numbers.
  • Encoding assumptions. Pretty JSON and HTML-CSS-JS Prettify both assume the document is UTF-8. Files saved with a byte-order mark (BOM) or in another encoding can produce odd indentation, broken characters, or a hard parse failure with no clear pointer to the offending byte.

None of these are deal-breakers on a clean, well-configured workstation, but they explain why a Sublime-only workflow sometimes feels fragile, especially on borrowed machines, in CI environments, or when handing a JSON document to a teammate whose setup differs from yours.

Format JSON in Your Browser with JSON Formatter

When the editor path gets in the way, the fastest reliable option is a browser-side JSON Formatter that formats, minifies, and validates in the same pass — and reports the exact line and column when something is wrong.

  1. Paste or type your JSON into the input box.
  2. Pick an indent style (2 spaces, 4 spaces, or Tab), then click Format to beautify — or click Minify to compress it to a single line.
  3. If the JSON is invalid, read the line and column shown in the error and jump back to your editor to fix it; otherwise copy the formatted or minified result with the Copy button.

Because the tool uses the browser's native JSON parser and serializer, the output is canonical JSON that round-trips losslessly — only the whitespace changes. Minifying strips every space and newline so the payload is as small as possible for network transfer or storage; formatting restores newlines and indentation so nested objects and arrays become readable. Everything happens locally: the JSON never leaves the page, so it is safe to format API responses, access tokens, or private config without uploading data to a backend.

Why JSON Fails to Validate (and How to Fix It)

JSON is standardized as RFC 8259 and ECMA-404, which is stricter than JavaScript object literals in a few common ways. Most "why won't this parse" moments trace to one of these.

MistakeLooks like JavaScript?Valid in JSON?
Trailing comma after the last itemYesNo
Single-quoted strings or keysYesNo — JSON requires double quotes
Unquoted object keysYesNo — keys must be quoted strings
Comments (// or /* */)YesNo — JSON has no comments
undefined, NaN, Infinity, DateYesNo — only six value types exist

The browser formatter points to the first problem with a precise line and column, which turns a fifteen-minute hunt into a two-second fix. One subtle limit worth flagging is not a bug in the formatter but a property of JavaScript itself: integers are parsed as IEEE-754 doubles, so any value larger than 9,007,199,254,740,991 (Number.MAX_SAFE_INTEGER) loses precision. A snowflake ID like 12345678901234567890 comes back as 12345678901234567000. If exact large integers matter — Twitter/X IDs, 64-bit database keys, invoice numbers above nine quadrillion — keep them as strings in your JSON rather than bare numbers.

A Practical Workflow for Sublime JSON Tasks

The honest answer is to use both. Keep a JSON plugin installed in Sublime for the 80 percent of cases where the input is already valid and you just want to tidy it up before saving; open the JSON Formatter in a browser tab the moment a payload refuses to parse, the encoding looks suspicious, or you need to minify before pushing to a server. Because the formatter is stateless and runs locally, it works on locked-down machines, guest profiles, and CI runners where installing a Sublime plugin is not an option.

For debugging sessions, formatting is what you reach for — a 5,000-character single-line response becomes a browsable tree the moment it is pretty-printed. For shipping, minifying is not just cosmetic: stripping indentation can shrink a typical API payload before gzip compression, which matters on mobile clients and metered connections. Both directions round-trip through the same engine, so the structural data is preserved exactly while only the whitespace changes.

Typical day-to-day uses cover debugging an API response, cleaning up a config file such as package.json or tsconfig.json, shrinking a payload before storage, and simply checking whether a blob is valid JSON at all before feeding it to code. Keeping the browser formatter as a fallback means the difference between a stuck Sublime session and a finished task in roughly the time it takes to paste, click, and copy.

Related reading: JSON to CSV Cheat Sheet: Rules, Limits, and a Quick Workflow.

Related reading: Is a JSON to Excel Converter Safe to Use Online?.