JSON Sorter
Sort JSON object keys in your browser, choose recursive or top-level ordering, and review duplicate-key warnings, order changes, path rows, and a key-depth chart.{{ sortedJson || sortedFallbackText }}
| Check | Value | Detail | Copy |
|---|---|---|---|
| {{ row.check }} | {{ row.value }} | {{ row.detail }} |
| Path | Change | Before | After | Detail | Copy |
|---|---|---|---|---|---|
{{ row.path }} |
{{ row.change }} | {{ row.before }} | {{ row.after }} | {{ row.detail }} | |
| The selected order rules did not change any object or array order. | |||||
| Path | Pointer | Type | Depth | Preview | Copy |
|---|---|---|---|---|---|
{{ row.path }} |
{{ row.pointer }} |
{{ row.type }} | {{ row.depth }} | {{ row.preview }} | |
| Sort a valid JSON document to populate the path ledger. | |||||
{{ resultJson }}
JSON object member order usually has no business meaning, but text order still matters when people compare files, review fixtures, prepare examples, or keep configuration changes readable. Sorting object keys creates a repeatable view of the same parsed data so diffs are easier to inspect and accidental reorder noise is easier to remove.
Key sorting should be treated as a review and formatting step, not as proof that the data is correct. Duplicate member names, parser differences, number serialization, and optional array sorting can all change what a receiving system sees. Strict JSON is the safer interchange target; cleanup mode is for human-edited drafts that need comments and trailing commas removed before standard JSON output is produced.
Arrays need extra care because array order is data, not just presentation. Preserving arrays keeps event lists, priority lists, and ordered samples intact. Sorting arrays by a property is useful only when the array contains records and the chosen property is the real order key.
A stable sorted file is best used with the audit, order-change, and path views. The sorted text answers how the data will look after reserialization; the review rows explain what changed, what was counted, and where duplicate or structural surprises remain.
How to Use This Tool:
Start with the parser mode, then choose the ordering rules before trusting the sorted text.
- Set Parser mode. Use Strict JSON for normal interchange data. Use JSONC cleanup only for draft configuration text where comments or trailing commas need to be removed before standard JSON output.
- Paste into JSON source, browse for a
.json,.jsonc, or.txtfile, drop one file onto the editor, or load Sample. File loading is limited to files smaller than 2 MB. - Choose Key order, Sort scope, and Key comparison. A-Z keys, Recursive object keys, and Unicode code-unit order are the best default for repeatable review.
- Leave Array handling on Preserve array order unless records in an array should be reordered by a field such as
id,name,priority, ormeta.rank. - Pick the Output format. Two spaces, four spaces, tabs, compact output, and a custom 0 to 10 space indent are available. Use End newline when the downloaded file should end with a final line break.
- Open Advanced when duplicate keys or path-preview size matter. Warn and sort reports repeated names, Block sorted output stops output when repeated names are found, and Ignore duplicate notes hides those warnings.
- Review the summary and result tabs. Sorted JSON is the formatted result, Sort Audit explains the parse and sort status, Order Changes lists the object or array paths whose order changed, Path Ledger lists paths and pointers, and Key Depth Chart shows structure by depth.
If the status says the input needs attention, fix the parser message first. If duplicate keys are blocked, remove or rename the repeated object member before relying on the sorted output.
Interpreting Results:
Sorted JSON is the reserialized value after parsing, key ordering, optional array ordering, indentation, and final newline settings. A result with 0 objects reordered can still be useful because it confirms the source was already in the selected order.
Sort Audit is the best confidence check before copying. It records parse status, key order, objects scanned and changed, array policy, structure size, payload size, cleanup notes, and duplicate-key details when they are not ignored.
Order Changes shows the exact object or array paths where sorting changed visible order, with before and after key or sort-value previews for review.
Path Ledger helps verify that the shape is still the one you expected. Paths use dot and bracket notation for quick reading, while pointers use slash-prefixed JSON Pointer notation for systems that already use that standard.
The false-confidence warning is repeated object names. Standard parsing can keep only the last value for a duplicate name before sorting, so a clean-looking sorted object may already have lost an earlier value. Use the duplicate-key policy and audit rows before treating the output as a safe handoff file.
Technical Details:
A JSON object is a collection of member names and values. JSON itself does not assign meaning to object member order, while arrays remain ordered sequences. Key sorting is therefore a text-normalization choice for objects, not a general statement that the data is more correct.
Deterministic sorting depends on the comparison rule. Unicode code-unit ordering compares raw string units without language collation, which makes it better for repeatable fixtures and signature-adjacent review. Case-insensitive and natural number-aware ordering are easier for humans to scan, but they are not a substitute for a formal canonical JSON rule required by another system.
Transformation Core:
| Stage | Rule | Review Point |
|---|---|---|
| Prepare source | Strict mode parses the text as standard JSON. Cleanup mode removes JavaScript-style comments and trailing commas before parsing. | Cleanup notes appear in Sort Audit, and output is still standard JSON. |
| Parse value | The source must produce one JSON value: object, array, string, number, boolean, or null. | Syntax failure stops sorted output and reports the parser message, with line and column when available. |
| Scan duplicate names | Repeated object member names are detected before parsing overwrites earlier values. | Duplicate key policy decides whether repeated names warn, block, or stay hidden. |
| Sort object keys | Object member names are sorted A-Z or Z-A at the selected scope. | Objects sorted and objects changed are counted separately, and changed paths appear in Order Changes. |
| Handle arrays | Array order is preserved by default. Record arrays can be sorted by a property when enabled. | Array sorting should be used only when that property defines the intended order. |
| Serialize output | The parsed value is written back as compact, indented, tab-indented, or custom-space JSON. | Whitespace is regenerated, and the custom space count is capped at 10. |
| Walk structure | The sorted value is counted by nodes, objects, arrays, scalars, keys, and depth. | Path Ledger and Key Depth Chart come from the sorted structure. |
Ordering Rules:
| Choice | Behavior | Consequence |
|---|---|---|
| Unicode code-unit order | Compares key strings by their raw code-unit values, then applies A-Z or Z-A direction. | Most repeatable for diffs, fixtures, and canonicalization-style review. |
| Case-insensitive order | Compares keys without case sensitivity first, then uses the original string as a tie-breaker. | Useful for reading mixed-case keys, but not a strict canonical order. |
| Natural number-aware order | Compares embedded numbers as numbers where possible, so names such as item2 can sort before item10. | Better for human labels and generated field names. |
| Recursive object keys | Sorts each object found at any depth, including objects inside arrays. | Best for whole-document diffs and nested configuration review. |
| Top-level object only | Sorts only the root object when the root is an object. | Preserves nested object member order for examples where inner order is intentional. |
| Property array sorting | Sorts eligible arrays of objects by a plain property or dot path. Missing or null values sort after matched values. | Changes data order, so it should be reserved for arrays that are unordered record sets. |
Path and Pointer Evidence:
| Ledger Field | Meaning | Use It For |
|---|---|---|
| Path | A readable dot or bracket path such as $.alpha.channels[0].name. | Finding values quickly while reviewing nested output. |
| Pointer | A JSON Pointer string where each token is prefixed by /, with ~ and / escaped inside tokens. | Matching paths used by JSON Patch, schemas, or systems that report pointer-style locations. |
| Type | The JSON value kind at that location: object, array, string, number, boolean, or null. | Checking whether a field changed shape after cleanup or sorting. |
| Depth | The nesting level from the root value. | Spotting unexpectedly deep data that may be hard to review or flatten later. |
| Preview | A compact summary of the value, such as object keys, array length, or short scalar text. | Confirming the path points to the intended part of the document. |
Do not treat the sorted output as a cryptographic canonical form unless the receiving system requires the same duplicate-key handling, Unicode ordering, array policy, number serialization, whitespace, and string escaping rules. A full canonicalization standard can be stricter than a review-oriented sorter.
Privacy Notes:
Pasted text and browsed or dropped files are read, parsed, sorted, charted, copied, and downloaded in the browser during the current session. No server lookup is needed for the sorting or path review itself.
Worked Examples:
An API configuration sample starts with keys in the order zebra, alpha, release, and limits. With A-Z keys, Recursive object keys, and Unicode code-unit order, Sorted JSON places object members in repeatable order at every depth, and Sort Audit reports how many objects were scanned and changed.
A wrapper object needs only its top-level keys cleaned up for a readme example. Choose Top-level object only so the root order changes while nested example objects keep their original member order. Path Ledger still lists the nested values so you can confirm the shape did not change.
A root array contains records with rank values. Switch Array handling to Sort root array by property and set Array sort property to rank. The summary names the number of arrays reordered; if a record has no rank, it sorts after records with a value.
A source object contains {"id":1,"id":2}. In warning mode, Sort Audit lists the duplicate key and sorted output keeps the parsed last value. In blocking mode, sorted output is withheld until the repeated name is fixed.
FAQ:
Does sorting JSON keys change the data?
Sorting object member names changes text order, not the parsed values. Array sorting is different because arrays are ordered data, so keep Preserve array order unless the array is a record set that should be sorted by a property.
Why did comments disappear from JSONC cleanup output?
Cleanup mode removes comments and trailing commas before parsing, then writes standard JSON. Comments and draft-only commas are not part of the final JSON value.
Which key comparison mode should I use for repeatable diffs?
Use Unicode code-unit order with the same A-Z or Z-A direction every time. Case-insensitive and natural ordering are easier to read in some documents, but they are review choices rather than strict canonical ordering.
Why does the duplicate-key warning matter?
A parser can keep only one value for a repeated object member name. The warning tells you the sorted text may already have lost an earlier value, so remove or rename the duplicate before using the output for handoff.
Does the sorter send my JSON anywhere?
The source text and selected file are handled in the browser for sorting, audit rows, the path ledger, and chart output. The tool does not need a server lookup to process the JSON document.
Glossary:
- Object member
- A JSON object name and value pair, often called a key and value in everyday use.
- Unicode code-unit order
- A deterministic string comparison based on raw code-unit values rather than human language collation.
- JSONC cleanup
- A draft-input mode that removes comments and trailing commas before standard JSON parsing.
- Duplicate key
- A repeated object member name inside the same object.
- Order Changes
- The result table that lists object or array paths whose visible order changed during sorting.
- JSON Pointer
- A slash-prefixed path syntax for identifying a value inside a JSON document.
- Path Ledger
- The result table that lists paths, pointers, value types, depth, and previews for the sorted structure.
- Key Depth Chart
- The chart that groups keys, objects, arrays, and scalars by nesting depth.
References:
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format, RFC Editor, December 2017.
- RFC 8785: JSON Canonicalization Scheme (JCS), RFC Editor, June 2020.
- RFC 6901: JavaScript Object Notation (JSON) Pointer, RFC Editor, April 2013.
- JSON.stringify(), MDN Web Docs.
- JSONC Specification, JSONC.org.