Sort JSON keys

Reorders object keys alphabetically, including nested objects and arrays of objects.

{{ jsonSort.message }}

Overview

When two JSONs represent the same data with keys in different orders, a text diff shows false differences where there is no semantic difference at all. This pollutes pull request reviews, breaks automatic comparisons in snapshot tests, and complicates audits. Sorting keys before saving removes that noise and makes diffs genuinely useful.

The sort is recursive: keys in nested objects are sorted too, and arrays of objects have each element's keys reordered individually. Plain value arrays such as strings or numbers are not reordered, because item positions in an array are semantically significant in most cases.

In projects with persisted JSON files, such as API mocks, test fixtures, and i18n translation files, keeping keys sorted as a team convention makes code review easier and reduces merge conflicts when multiple contributors or tools edit the same file. Some teams enforce this via lint with prettier, which can sort JSON keys automatically on save.

A technical note: the ECMAScript spec does not guarantee key order in objects. In practice, however, all modern engines including V8, SpiderMonkey, and JavaScriptCore preserve insertion order for non-numeric string keys. After sorting and re-parsing, the order holds. For machine-to-machine communication this is irrelevant, but for human reading and diffing it makes all the difference.

Technical deep dive

Common questions summarized

  • What is this tool for?: It runs fully in your browser: useful to validate, format, or convert data in everyday development.
  • Are my inputs sent to a server?: Processing happens locally with JavaScript. We do not store what you paste into the text areas.
  • Can I use this for real production data?: Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.

Sample payload to try

  • See also the larger "Code Snippets" sample; paste this excerpt to try locally: Effect — {"z":1,"a":{"m":2,"b":3}} → chaves a, z e depois b, m

Tool guide

  • What JSON is See above. In JSON objects, key order has no fixed semantic meaning in the spec, but it affects diffs and readability.

  • What the tool does Walks objects (including nested ones) and sorts keys alphabetically. Arrays keep element order.

  • Why use it Stable diffs between file versions, less noise in reviews, and automated config comparisons.

Code Snippets

Code example
{"z":1,"a":{"m":2,"b":3}} → chaves a, z e depois b, m

Effect

{"z":1,"a":{"m":2,"b":3}} → chaves a, z e depois b, m

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.