JSON
JSON Sort Keys
เรียงคีย์ของอ็อบเจกต์ใน JSON ตามตัวอักษรแบบเรียกซ้ำ — ลำดับอิลิเมนต์ในอาร์เรย์ไม่เปลี่ยน มีเพียงคีย์ของอ็อบเจกต์ในแต่ละระดับที่ถูกเรียง
JSON doesn't guarantee object key order, so two semantically identical documents can look different simply because their fields are in a different order. This tool recursively sorts object keys alphabetically at every nesting level, without touching array element order.
How to use it
- Paste JSON and its object keys are sorted alphabetically instantly, at every level of nesting.
- Pick ascending or descending order as needed.
- Array element order is left untouched — only object keys are sorted, not array values.
Common uses
- Bringing JSON into a canonical form before comparing it with git diff or a text diff tool.
- Normalizing a configuration file for a stable, predictable look in a repository.
- Preparing JSON before computing a content hash, when the result needs to be deterministic regardless of input field order.
Things to keep in mind
Sorting is byte-based (by Unicode code point) — all uppercase letters come before lowercase ones regardless of alphabet, unlike locale-aware sorting.
Only object keys are sorted — array element order carries semantic meaning in JSON, so it's never changed.
บทความเกี่ยวกับเครื่องมือนี้: JSON Sort Keys: เหตุใดจึงต้องเรียงลำดับคีย์ของอ็อบเจกต์
คำถามที่พบบ่อย
ทำไมฉันถึงอยากเรียงคีย์ของ object JSON ตามตัวอักษร?
การเรียงคีย์ช่วยให้เปรียบเทียบไฟล์ JSON สองไฟล์ได้อย่างมีความหมายมากขึ้น เพราะปกติแล้วลำดับคีย์ขึ้นอยู่กับวิธีสร้าง object แต่แรก แม้จะไม่กระทบความหมายก็ตาม
การเรียงคีย์เปลี่ยนความหมายของ JSON หรือไม่?
ไม่ ใน JSON ลำดับคีย์ของ object ไม่มีนัยสำคัญเชิงความหมาย การเรียงเปลี่ยนแค่หน้าตาของข้อมูล ไม่ใช่สิ่งที่มันแทน
เครื่องมือนี้ส่ง JSON ของฉันไปที่ไหนเพื่อเรียงลำดับหรือไม่?
ไม่ การเรียงลำดับทำงานทั้งหมดในเบราว์เซอร์ของคุณ ไม่มีการส่งข้อมูลไปยังเซิร์ฟเวอร์
การเรียงคีย์ทำงานแบบเรียกซ้ำในทุกระดับความลึกหรือไม่?
ใช่ การเรียงลำดับใช้กับคีย์ในทุกระดับ ไม่ใช่แค่ระดับบนสุด — รวมถึงคีย์ของ object ที่ซ้อนกันทุกระดับความลึกด้วย มิฉะนั้นผลลัพธ์จะไม่สอดคล้องกัน
ภาษา/โลแคลมีผลต่อลำดับของคีย์ที่เรียงแล้วหรือไม่?
การเรียงตามไบต์ (ตามรหัส Unicode) จะจัดตัวพิมพ์ใหญ่ทั้งหมดไว้ก่อนตัวพิมพ์เล็กเสมอไม่ว่าตัวอักษรจะเป็นอะไร ซึ่งต่างจากการเรียงแบบคำนึงถึงกฎทางภาษาที่จัดลำดับตัวอักษรแบบ "เป็นธรรมชาติ" มากกว่า — สำหรับคีย์ทางเทคนิคส่วนใหญ่ความแตกต่างนี้แทบไม่มีผล แต่ควรคำนึงถึงสำหรับชื่อที่ไม่ใช่ภาษาละติน