Skip to main content
Yoryantra
← Back to Tools

JSON Sort Keys Tool

Sort every JSON object key deterministically while preserving array order and value meaning.

Object keys are sorted recursively. Array elements stay in their original sequence, including arrays of objects.

Output order and spacing

Sorted JSON

Recursively sorted JSON will appear here.
Parsing and sorting run in your browser. The page does not send the JSON you paste to a processing API.
Not canonical JSON: deterministic key order is only one part of canonicalization. RFC 8785 also defines primitive serialization and other constraints, so do not use this output as a signing or hashing canonical form.

Sorting object members is presentation; array order is data

JSON objects are defined as unordered collections of name/value pairs, while arrays are ordered sequences. That difference is why every object can be sorted recursively without moving a single array element. A deployment step list, priority list, breadcrumb sequence, or test case array keeps its original order.

The distinction comes directly from RFC 8259. Member order can still matter to humans and diff tools, but software should not depend on JSON object ordering for data meaning.

The comparison is locale-independent and deterministic

Human-language collation can vary by locale, browser, and accent rules. Keys here are compared by raw JavaScript UTF-16 string values instead. That gives the same ordering rule for the same input rather than asking the runtime whether, for example, an accented letter should sort beside its unaccented form.

Ascending order follows the same UTF-16 value-comparison idea used by the property-sorting step in RFC 8785 JSON Canonicalization Scheme. Descending order is provided for inspection, but it is not JCS canonicalization.

Two inputs are rejected before they can be silently changed

Duplicate object names

JSON member names should be unique for interoperable data. Browser parsers commonly keep one value when names repeat, so duplicate names are detected before parsing and sorting instead of quietly discarding an earlier member.

Numbers that would lose their decimal value

JavaScript parses JSON numbers as binary64 numbers. If converting a numeric token to JavaScript and back would change its exact decimal value, sorting stops and asks you to represent that value as a string or use a lossless parser.

Clean diffs are a good reason to sort; signatures are not

Recursive key ordering can make generated fixtures, configuration snapshots, debugging captures, and review diffs easier to scan. It is also useful when two systems emit the same object members in different presentation orders.

Cryptographic canonicalization is a different job. JCS fixes much more than property order, including how numbers and strings are serialized. A visually stable sort should not be substituted for a protocol's required canonical form.

Limits and serialization details

  • Input must be valid JSON; comments, trailing commas, NaN, and Infinity are not valid JSON syntax.
  • String escape spelling may normalize in output because the parsed string value is serialized again.
  • Negative zero is rejected because JSON serialization through JavaScript would turn it into 0.
  • Processing stops beyond 25,000 values or 120 nested levels to protect page responsiveness.