JSON Formatter
Paste JSON to format, minify, or validate it locally.
JSON Formatter — what it does
Format JSON into indented, readable structure, minify it back to a single line, or validate it and find out exactly where it breaks. Most JSON problems are a missing comma or a stray trailing one, and a validator that points at the position saves the squinting.
Worked example
A one-line order record as returned by an API, run through Format (2-space indentation).
Input — JSON input
{"order_id":1004,"customer":{"name":"Dev Patel","email":"dev.patel@example.com"},"items":[{"sku":"PEN-BOX","qty":20,"unit_price":2.10}],"paid":false,"notes":null}Output — Format
{
"order_id": 1004,
"customer": {
"name": "Dev Patel",
"email": "dev.patel@example.com"
},
"items": [
{
"sku": "PEN-BOX",
"qty": 20,
"unit_price": 2.1
}
],
"paid": false,
"notes": null
}Formatting re-serialises the data, so 2.10 comes back as 2.1; Minify returns the same object on one line, and Validate prints 'Valid JSON'.
When this tool helps
- Making an API response readable while debugging a request.
- Finding the syntax error in a configuration file that an application refuses to load.
- Minifying a JSON payload before embedding it in code or sending it over the wire.
How to use it
- Paste the JSON into the input box.
- Choose format, minify or validate.
- Read the output or the validation message.
- Copy the result back into your file or request.
Accuracy, limits, and good practice
- JSON forbids trailing commas and comments, which is why files copied from JavaScript so often fail to parse.
- Keys must be in double quotes — single quotes are valid JavaScript and invalid JSON, and this trips up hand-written payloads constantly.
- Formatting does not change meaning: key order and whitespace carry no semantics, so a reformatted document is the same document.
Frequently asked questions
Why is my JSON invalid when it looks fine?
Usually a trailing comma, a single-quoted string, an unquoted key, or a smart quote pasted in from a word processor.
Should I minify JSON for production?
For payloads sent over the network, yes. For configuration files a human maintains, readability is worth far more than the bytes.
What does an error message look like?
The browser's own parser message, prefixed with Error:. A trailing comma after the last property gives: Error: Expected double-quoted property name in JSON at position 36 (line 3 column 1). The position counts characters from the start of the box.
What happens with an empty input box?
A completely empty box is treated as {}: Validate says Valid JSON and Format outputs {}. A box containing only spaces or line breaks is not empty and produces an unexpected-end-of-input error.
Related tools on this site
- CSV Duplicate Remover — Remove duplicate rows using a selected key column
- CSV Row Filter — Keep CSV rows that match a selected rule
- HTML Table to CSV — Extract an HTML table and download it as a CSV file
Further reading: Cleaning a CSV export before you import it anywhere · CSV, JSON, YAML, XML and Markdown Tables: When Each Fits and How to Convert
Everything above runs inside this page. JSON Formatter needs no account, no upload, and no server round trip — close the tab and nothing is left behind.
JSON 格式化能做什麼
把 JSON 排成有縮排、易讀的結構,壓回單行,或直接驗證並指出它壞在哪裡。多數 JSON 問題不過是少一個逗號或多一個尾逗號,有個會指出位置的驗證器,就不必再瞇著眼找。
實際範例
API 回傳的一行訂單記錄,按下「格式化」(2 個空格縮排)後的結果。
輸入:JSON
{"order_id":1004,"customer":{"name":"Dev Patel","email":"dev.patel@example.com"},"items":[{"sku":"PEN-BOX","qty":20,"unit_price":2.10}],"paid":false,"notes":null}輸出:格式化
{
"order_id": 1004,
"customer": {
"name": "Dev Patel",
"email": "dev.patel@example.com"
},
"items": [
{
"sku": "PEN-BOX",
"qty": 20,
"unit_price": 2.1
}
],
"paid": false,
"notes": null
}格式化會重新序列化資料,所以 2.10 變成 2.1;「壓縮」會把同一個物件放回一行,「驗證」則顯示 Valid JSON。
什麼時候用得上
- 除錯請求時,把 API 回應變得可讀。
- 找出應用程式拒絕載入的設定檔中的語法錯誤。
- 把 JSON 載荷壓縮後再嵌進程式碼或送上網路。
使用步驟
- 把 JSON 貼進輸入框。
- 選擇格式化、壓縮或驗證。
- 閱讀輸出或驗證訊息。
- 把結果複製回檔案或請求中。
精確度、限制與實務建議
- JSON 不允許尾逗號與註解,這也是從 JavaScript 複製過來的檔案常常解析失敗的原因。
- 鍵名必須用雙引號——單引號在 JavaScript 合法、在 JSON 非法,手寫載荷極常栽在這裡。
- 格式化不改變意義:鍵順序與空白沒有語意,重排後仍是同一份文件。
常見問題
看起來沒問題,為什麼說我的 JSON 無效?
通常是尾逗號、單引號字串、沒加引號的鍵名,或從文書軟體貼進來的智慧引號。
正式環境該壓縮 JSON 嗎?
要透過網路傳送的載荷該壓。人工維護的設定檔則以可讀性優先,遠比省那點位元組值得。
錯誤訊息長什麼樣子?
是瀏覽器剖析器本身的訊息,前面加上 Error:。最後一個屬性後多了逗號會得到:Error: Expected double-quoted property name in JSON at position 36 (line 3 column 1)。position 是從輸入框開頭算起的字元位置。
輸入框空白會怎樣?
完全空白的輸入框會當成 {}:驗證顯示 Valid JSON,格式化輸出 {}。若只含空格或換行則不算空白,會得到 unexpected end of input 的錯誤。
本站相關工具
- CSV 重複資料移除 — 依指定欄位移除重複資料列
- CSV 資料篩選 — 依指定條件保留符合的 CSV 資料列
- HTML 表格轉 CSV — 提取 HTML 表格內容並下載為 CSV 檔案
延伸閱讀: 匯入之前先把 CSV 匯出檔清乾淨 · CSV、JSON、YAML、XML 與 Markdown 表格:各自適用的場合與轉換方法
以上步驟全部在這個頁面內完成,JSON 格式化 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。