JSON Sorter
Sort JSON and clean JSONC in your browser with repeatable key rules, duplicate-name warnings, and optional record-array ordering.{{ summaryTitle }}
{{ summaryLine }}
{{ computation.values.sorted_text }}
| Check | Value | Meaning | Copy |
|---|---|---|---|
| {{ row.check }} | {{ row.value }} | {{ row.detail }} |
| Path | Change | Before | After | Detail | Copy |
|---|---|---|---|---|---|
{{ row.path }} | {{ row.change }} | {{ row.before }} | {{ row.after }} | {{ row.detail }} |
| Path | Pointer | Type | Depth | Preview | Copy |
|---|---|---|---|---|---|
{{ row.path }} | {{ row.pointer }} | {{ row.type }} | {{ row.depth }} | {{ row.preview }} |
The chart renderer is unavailable. The same structure remains available in the path ledger and CSV export.
Introduction:
A noisy JSON diff can hide a small data change. Two objects may contain the same names and values while listing their members in a different order, causing reviewers to scan lines that did not change semantically. Repeatable member ordering makes configuration, fixtures, API examples, and generated files easier to compare.
Sorting must respect the difference between objects and arrays. Object member order is usually presentation rather than data meaning. Array position is data: moving the first record to the third position can change priority, chronology, or the meaning assigned by a receiving system. For that reason, array order should remain untouched unless a real record property defines the intended sequence.
- JSON value
- One object, array, string, number, boolean, or null after the text has been parsed.
- Object member
- A name and value inside braces. Member names should be unique for reliable interchange.
- JSONC draft
- JSON-like text with comments or trailing commas. Those additions must be removed before standard JSON parsing.
- JSON Pointer
- A slash-prefixed route to a value, with special escaping for tilde and slash characters.
Duplicate member names are more serious than untidy order. Receivers may keep the last value, reject the object, or expose every duplicate. Once a normal parser keeps only one value, sorting cannot reconstruct the discarded entries. Duplicate review therefore belongs before a sorted document is trusted.
Comparison rules also change the visible order. Raw code-unit comparison is useful for repeatable fixtures. Case-insensitive English comparison groups names that differ mainly by case. Natural number-aware English comparison places labels such as item2 before item10. None of these choices creates a universal canonical JSON representation.
Parsing and serialization regenerate whitespace, escaping, and number text. Sorting is useful for readable consistency, but it is not byte preservation and should not replace a protocol's exact canonicalization rules for hashes, signatures, cache keys, or security decisions.
How to Use This Tool:
Choose the parser path first, then define which object and array positions are allowed to change.
- Paste one JSON value or load one JSON, JSONC, or TXT file up to 2 MiB. Select JSON for strict input, JSONC cleanup for a known draft, or Auto detect to try strict JSON before cleanup.
- Choose Key order, Sort scope, and Key comparison. Recursive scope sorts eligible object names at every depth; top-level scope limits intentional key sorting to the root object.
- Leave Array handling at Preserve array order unless record order should follow a property. For property sorting, enter a plain name or dot path such as
rankormeta.priority. - Choose indentation and the final-newline setting. Open Advanced to warn, block, or hide notes for duplicate names; use blocking when losing a repeated value would make the handoff unsafe.
- Read the parser status and Sort audit before copying the result. Fix syntax failures first, and fix duplicate names whenever the sorted value must preserve every intended member.
Interpreting Results:
Sorted document is the parsed value serialized with the selected object-key, array, indentation, and newline rules. Zero changed objects means the eligible objects already matched the requested order.
- Use Sort audit to confirm the resolved input format, comparison rule, cleanup notes, changed-object count, array changes, duplicates, and byte-size change.
- Use Order changes to see which object or record-array sequences actually moved.
- Use Path ledger when nested shape matters. Its readable path and JSON Pointer identify the same location in two different notations.
A successful sort proves that one value parsed and the requested transform completed. It does not prove that field names are correct, values satisfy a schema, numbers kept application-specific precision, or a receiver will accept the document.
Technical Details:
Sorting is a parse-transform-serialize operation. The input text first becomes a tree of JSON values. Eligible object names and, optionally, record arrays are reordered in that tree. A new text document is then written from the transformed value.
Transformation Core
| Stage | Exact behaviour | What can change |
|---|---|---|
| Resolve text | Strict JSON parses as written. JSONC cleanup removes line comments, block comments, and commas immediately before } or ], without treating comment marks inside strings as comments. | Comments and trailing commas disappear. |
| Scan duplicates | Repeated names are detected in each object before normal parsing can collapse them. | Warn and ignore still allow parsing; block stops output. |
| Parse value | The cleaned or strict text must resolve to one JSON value. | Number text, escaping, and whitespace become parsed values. |
| Sort objects | Eligible member names use the selected direction and comparator. Recursive scope visits objects inside arrays as well as objects inside objects. | Member sequence changes; values remain attached to their names. |
| Sort records | Only eligible arrays containing objects can sort by the chosen property path. Missing and null property values follow matched values; ties retain original order. | Record sequence can change when array sorting is enabled. |
| Serialize | The transformed tree is written with compact output, tabs, 2 or 4 spaces, or 0 to 10 custom spaces, plus an optional final newline. | All source indentation and insignificant whitespace are regenerated. |
| Analyse | The sorted tree is walked to count nodes, objects, arrays, scalars, keys, and maximum depth and to build paths and pointers. | Audit metrics describe the output tree, not source formatting. |
A compact path illustrates the transformation. The JSONC draft {"b":2,/* note */"a":1,} loses the comment and trailing comma, parses to one object, sorts its names A-Z, and serializes as {"a":1,"b":2} in compact mode.
Rule Core
| Comparison | Primary rule | Tie rule |
|---|---|---|
| Unicode code-unit order | Compare the full strings with raw code-unit ordering. | Equality only when the strings are identical. |
| Case-insensitive English | Use English locale comparison with base sensitivity. | Use raw code-unit order when distinct names compare equally. |
| Natural number-aware English | Use English locale comparison with base sensitivity and numeric chunks. | Use raw code-unit order when distinct names compare equally. |
| Z-A direction | Multiply the selected comparison result by -1. | The same direction also applies to property-sorted arrays. |
| Policy | Rule | Important limit |
|---|---|---|
| Warn and sort | Report duplicate paths and continue with the parsed value. | A normal parser retains only one value for a repeated name. |
| Block sorted output | Stop before sorting when one or more duplicate names are found. | The source must be corrected before output is available. |
| Ignore duplicate notes | Continue parsing and omit duplicate detail rows. | The duplicate count still exists; hidden notes do not restore discarded values. |
| Preserve arrays | Keep every array sequence while still sorting eligible object names inside array items. | This is the default. |
| Property-sort arrays | Sort the root array or every eligible object array by a property or dot path. | Arrays containing non-object items are left in place. |
JSON Pointer begins at the root and prefixes each reference token with /. A tilde in a member name becomes ~0, and a slash becomes ~1. The readable path uses dot notation for identifier-like names and bracket notation for other names.
The path-ledger preview accepts 25 to 500 rows, but that display limit does not change the transform. Input size is measured in UTF-8 bytes and must not exceed 2 MiB.
Privacy and Data Limits:
Pasted text and selected files are read and sorted in the browser. The JSON content is not uploaded for the transformation.
- The 2 MiB limit applies to UTF-8 input bytes, not the number of visible characters.
- Parsing rewrites number text through the browser's numeric representation. Very large integers or unusually precise decimals may not round-trip exactly.
- Comments, trailing commas, indentation, spacing, and original escape spelling are not preserved.
- Sorting is not schema validation and is not a formal canonicalization scheme.
- Property paths use dot-separated names and do not provide escaping for a literal dot inside a member name.
Worked Examples:
Configuration draft cleanup
A JSONC settings draft contains explanatory comments and trailing commas. Choose JSONC cleanup, recursive A-Z code-unit sorting, and 2-space output. The audit names the removed draft syntax, while the sorted document becomes standard JSON with regenerated indentation.
Ranked records with missing values
A root array contains objects with numeric meta.rank values, plus one object without that path. Select root-array property sorting and enter meta.rank. Numeric ranks sort in the chosen direction, equal ranks keep their original order, and the record without a rank follows the matched records.
References:
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format, RFC Editor, December 2017.
- RFC 6901: JavaScript Object Notation (JSON) Pointer, RFC Editor, April 2013.