PDFのミカタ

キーの順番をそろえる方法

公開日:2026年10月19日|最終更新:2026年10月19日|運営者情報

この記事のポイント
  • 貼る
  • 印をつける

2つのJSONを比べたいのに、項目の並び順が違うだけで、差分が大量に出てしまう。そんなときは、JSONを整える・チェックする の「キーの順番を並べ替える」で、順番をそろえてから比べます。

手順

  1. 「整える前」に、JSONを貼り付けます。
  2. 「キーの順番を並べ替える」にチェックを入れます。
  3. 「整える」を押します。
  4. 「整えた後」に、項目名の順に並んだJSONが出ます。
  5. 「結果をコピー」でコピーします。
並べ替えは、項目名の順(辞書順)です。入れ子の中の項目も、並べ替えられます。

並べ替えの効果

比較の手順

  1. 比べたい2つのJSONを、それぞれ「キーの順番を並べ替える」で整える。
  2. 整った結果を、2つの文章の差分を調べるツールに貼り付ける。
  3. 本当の違いだけが、表示される。

並べ替えても変わらないこと

注意すること

向いている場面

例

2つのシステムが出力したJSONを比べたかった。項目の並びが違うため、見た目では分からなかった。両方を並べ替えてから比べたところ、実際に違う項目は1つだけだった。

つまずきやすい点

よくある質問

数字の項目名は、どう並びますか?

文字として並びます。「10」は「2」より前になります。

まとめ

比べる前に、キーの順番をそろえる。配列の順序は、変わりません。

JSONを整える・チェックするを使う(無料)

あわせて使えるツール

この解説が役に立ったら、応援してもらえるとうれしいです。

応援する(300円)ほしい物リストで応援

同じツールの、ほかの解説

解説の一覧を見る

How to Sort the Keys

Published: Oct 19, 2026 | Updated: Oct 19, 2026 | About (Japanese)

Key points
  • Paste
  • Tick

You want to compare two JSONs, but a mass of differences appears just because item order differs. In that case, align the order first with "Sort keys" in Format and Validate JSON and then compare.

Steps

  1. Paste the JSON into "Before".
  2. Tick "Sort keys".
  3. Press "Format".
  4. JSON with items in name order appears under "After".
  5. Copy it with "Copy result".
Sorting is by item name (dictionary order). Items inside nesting are sorted too.

Effects of sorting

Steps for comparing

  1. Format each of the two JSONs with "Sort keys".
  2. Paste the results into the tool that finds differences between two texts.
  3. Only the real differences are shown.

What does not change with sorting

Cautions

Good for

Example

Wanted to compare JSON output by two systems. Item order differed, so it was unclear by eye. After sorting both and comparing, only one item actually differed.

Common stumbling blocks

Frequently asked questions

How are numeric item names ordered?

As characters. "10" comes before "2".

Summary

Align key order before comparing. Array order doesn't change.

Use "Format and Validate JSON" (free)

Tools that go well with this

If this guide helped, a small tip would mean a lot.

Send a tip (¥300)Send a gift (Amazon wishlist)

More guides for this tool

See all guides