Developer Tools

JSON Sorter Online

Alphabetize JSON object keys with custom sorting, natural ordering, and full integer key preservation.

  • Runs in your browser
  • Free, no signup
Sort JSON Object Keys
Original JSON 26 lines
Alphabetically Sorted 26 lines
{
  "apple": "Red fruit",
  "banana": "Yellow fruit",
  "details": {
    "address_line_1": "100 Market St",
    "address_line_2": "Suite 400",
    "city": "San Francisco",
    "country": "USA",
    "zip_code": "94016"
  },
  "is_active": true,
  "mango": "Tropical fruit",
  "numeric_codes": {
    "2": "Secondary",
    "10": "Primary",
    "100": "Continue",
    "200": "OK",
    "500": "Server Error"
  },
  "tags": [
    "database",
    "backend",
    "cache"
  ],
  "zebra": "Striped mammal"
}

Sorting runs entirely in your browser using local JavaScript — your JSON files and data payloads are never uploaded to any server.

Comparing JSON files, generating reproducible API snapshots, and cleaning configuration files is significantly easier when object keys appear in consistent, deterministic order. This tool sorts JSON object keys alphabetically (A-Z or Z-A) or using natural numerical sorting.

Unlike standard JavaScript formatters that suffer from V8 engine numeric-key ordering quirks (which force integer keys into numeric order regardless of sort preferences), ToolDuck employs a custom recursive serializer that preserves your chosen sort criteria across all key types. Choose between recursive deep sorting or top-level only, with array order carefully preserved.

How to use this tool

  1. Paste your unsorted JSON into the original JSON editor or click "Load Sample".
  2. Select your desired sorting order: A → Z (Ascending) or Z → A (Descending).
  3. Choose your scope: "Recursive" to sort all nested objects throughout the tree, or "Top-Level Only".
  4. Configure options such as Natural Sort (key1, key2, key10) and Case Sensitivity in the toolbar.
  5. Click "Copy" to copy the sorted JSON to your clipboard, or "Download" to save a sorted .json file.

Alphabetical vs. Natural Key Ordering

Standard alphabetical sorting compares characters strictly by unicode codepoint, placing "item10" before "item2". In contrast, Natural Sort recognizes numbers embedded within strings and sorts them in intuitive human order ("item2" before "item10").

ToolDuck gives you full control with an optional Natural Sort toggle and customizable Case Sensitivity, ensuring your configuration files conform exactly to your team's conventions.

Bypassing the V8 JavaScript Integer Key Ordering Quirk

In modern JavaScript engines (including V8 in Chrome and Node.js), standard JavaScript objects iterate integer-like string keys (e.g. "10", "2", "100") in ascending numerical order, ignoring insertion and alphabetical sorting order when using JSON.stringify().

ToolDuck solves this engine limitation by utilizing a custom AST stringifier that directly writes out sorted keys in the exact order selected, guaranteeing 100% deterministic, predictable output across all JavaScript runtimes.

Preserving Sequence Integrity in JSON Arrays

According to the RFC 8259 JSON specification, arrays are ordered sequences where element order carries semantic meaning (e.g., chronological events, ranked priorities, or coordinate pairs). Arbitrarily sorting arrays can corrupt application logic.

The JSON Sorter strictly preserves the order of elements within arrays while deeply sorting the keys of any objects contained inside them.

100% In-Browser Privacy and Security

Configuration files, translation catalogs, and API responses often contain proprietary business rules, tokens, and client credentials. Never compromise security by uploading files to untrusted online formatters.

ToolDuck executes all parsing, sorting, and serialization locally within your web browser. No network requests are made, keeping your confidential information private.

Frequently asked questions

Does this tool sort elements inside arrays?

No. In JSON, arrays represent ordered lists where position is significant. The sorter maintains array element sequence exactly as provided, while sorting the keys of any objects found inside the array.

What is the difference between Recursive and Top-Level sorting?

Top-Level sorting only alphabetizes keys in the outermost JSON object, leaving nested child objects untouched. Recursive sorting traverses the entire JSON hierarchy, sorting keys in all nested child objects.

How does Natural Sorting work?

Natural sorting sorts multi-digit numbers embedded in keys by their numerical value rather than character by character. For example, "chapter2" appears before "chapter10", which is much more readable for configuration files.

Can I choose different indentation spacing?

Yes. Choose between 2 spaces, 4 spaces, or minified output directly from the Indent dropdown menu.

Are my JSON files uploaded to any server?

No. All processing occurs exclusively in your browser using local JavaScript. Your data is never sent over the network.