JSONを見やすく整える方法(無料)
- 貼る
- 選ぶ
- コピーする
APIの結果や設定ファイルのJSONが、1行にぎっしり詰まっていて読めない。JSONを整える・チェックする は、JSONを字下げして見やすく整え、書き方が正しいかもチェックするツールです。貼り付けた内容は、この端末の中で処理します。どこにも送られません。
手順
- 「整える前」に、JSONを貼り付けます。
- 「字下げ」で、「スペース2つ」「スペース4つ」「タブ」から選びます。
- 必要なら、「キーの順番を並べ替える」にチェックを入れます。
- 「整える」を押します。
- 「整えた後」に結果が出ます。「結果をコピー」でコピーします。
JSONとは
プログラムやWebサービスで、よく使われるデータの書き方です。「項目名: 値」の形で書き、波かっこ { } や角かっこ [ ] で囲みます。
整える効果
- 入れ子の構造が、字下げで一目で分かる
- どの項目が、どこに属するか見える
- 書き間違いを、見つけやすい
字下げの選び方
- スペース2つ:コンパクト。Web系で多い。
- スペース4つ:読みやすい。多くのコードで標準。
- タブ:タブ幅を自由に変えたい場合。
向いている場面
- APIの応答を、読みやすくする
- 設定ファイルの、確認や編集
- JSONの書き方が合っているかのチェック
- 他の人に、JSONを共有する前の整形
例
APIから返ってきた、1行のJSONを貼り付けた。「スペース2つ」で整えると、入れ子の構造が分かり、目的の項目をすぐに見つけられた。
つまずきやすい点
- 「JSONの形が正しくありません」と出る:別の解説で、よくある間違いを説明しています。
- 日本語が「\u」の記号になる:貼り付けた元の形式のまま。内容は同じ。
- 大きなJSONで重い:端末のメモリによる。
よくある質問
整えると、データの中身は変わりますか?
いいえ。見た目の空白と改行が変わるだけです。(「キーの順番を並べ替える」を選ぶと、順番が変わります)
貼り付けた内容は、送られますか?
いいえ。ブラウザの中で処理します。
まとめ
貼り付けて、字下げを選んで、「整える」。正しさのチェックも、同時にできます。
JSONを整える・チェックするを使う(無料)あわせて使えるツール
- CSVとJSONを相互変換する:CSVとJSONを、すぐに相互変換します。
- ファイルとBase64を相互変換する:ファイルとBase64の文字を相互に変換します。
- 重複した行を消す・並べ替える:重複した行を消して、並べ替えます。
同じツールの、ほかの解説
How to Format JSON (Free)
- Paste
- Choose
- Copy
JSON from an API or a configuration file is crammed onto one line and unreadable. Format and Validate JSON indents JSON to make it readable and also checks whether it is written correctly. What you paste is processed inside this device and sent nowhere.
Steps
- Paste the JSON into "Before".
- Under "Indent", choose from "2 spaces", "4 spaces" and "Tab".
- If needed, tick "Sort keys".
- Press "Format".
- The result appears under "After". Copy it with "Copy result".
What JSON is
A way of writing data often used in programs and web services. Written in the form "name: value" and enclosed in braces { } or brackets [ ].
Benefits of formatting
- The nested structure is clear at a glance through indentation
- You can see which item belongs where
- Typing mistakes are easier to find
Choosing the indent
- 2 spaces: compact. Common in web work.
- 4 spaces: readable. Standard in much code.
- Tab: when you want to freely change the tab width.
Good for
- Making an API response readable
- Checking and editing configuration files
- Checking that JSON is written correctly
- Formatting JSON before sharing it with others
Example
Pasted one-line JSON returned from an API. Formatting with "2 spaces" showed the nested structure and let me find the target item at once.
Common stumbling blocks
- "The JSON is malformed" appears: a separate guide explains common mistakes.
- Japanese appears as "\u" codes: it stays in the form it was pasted. The content is the same.
- Heavy with large JSON: depends on the device's memory.
Frequently asked questions
Does formatting change the data's contents?
No. Only the visible spaces and line breaks change. (Choosing "Sort keys" changes the order.)
Is what I paste sent?
No. It is processed inside the browser.
Summary
Paste, choose the indent and press "Format". It also checks correctness at the same time.
Use "Format and Validate JSON" (free)Tools that go well with this
- Convert CSV and JSON: Convert between CSV and JSON instantly.
- Convert Files and Base64: Convert between files and Base64 text.
- Remove Duplicate Lines and Sort a List: Remove duplicate lines and sort them.