JSON to sort

(number of spaces, 0 for compact)

Sorted JSON

How does it work?

This tool sorts the keys of a JSON object alphabetically. It works recursively, so nested objects will also have their keys sorted. Arrays are preserved in their original order, but any objects within arrays will have their keys sorted.

The sorting follows these rules:

  • All object keys are sorted alphabetically (A-Z)
  • Nested objects have their keys sorted recursively
  • Array order is preserved, but objects within arrays are sorted
  • The JSON structure and values remain unchanged
  • You can adjust the indentation for the output format

Example

Consider this JSON with unsorted keys:

{
  "name": "John Doe",
  "age": 30,
  "isActive": true,
  "address": {
    "street": "123 Main St",
    "city": "New York",
    "country": "USA",
    "zipCode": "10001"
  },
  "hobbies": ["reading", "swimming", "coding"],
  "contact": {
    "email": "john@example.com",
    "phone": {
      "home": "555-1234",
      "work": "555-5678",
      "mobile": "555-9012"
    }
  },
  "education": [
    {
      "degree": "Bachelor",
      "field": "Computer Science",
      "year": 2015
    },
    {
      "degree": "Master",
      "year": 2017,
      "field": "Data Science"
    }
  ]
}

After sorting the keys alphabetically:

{
  "address": {
    "city": "New York",
    "country": "USA",
    "street": "123 Main St",
    "zipCode": "10001"
  },
  "age": 30,
  "contact": {
    "email": "john@example.com",
    "phone": {
      "home": "555-1234",
      "mobile": "555-9012",
      "work": "555-5678"
    }
  },
  "education": [
    {
      "degree": "Bachelor",
      "field": "Computer Science",
      "year": 2015
    },
    {
      "degree": "Master",
      "field": "Data Science",
      "year": 2017
    }
  ],
  "hobbies": [
    "reading",
    "swimming",
    "coding"
  ],
  "isActive": true,
  "name": "John Doe"
}

This tool is useful for:

  • Standardizing JSON data for consistent formatting
  • Making JSON files easier to read and navigate
  • Comparing JSON structures by normalizing key order
  • Preparing JSON for version control to minimize diff changes
  • Organizing configuration files or API responses

Indentation Options

You can control the formatting of the output JSON by adjusting the indentation size:

  • 2 spaces (default): Standard indentation for most JSON
  • 4 spaces: Wider indentation for better readability
  • 0 spaces: Compact JSON with no whitespace (minified)

Note:

This tool only sorts the keys of JSON objects. It does not sort array values or modify the actual data in any way. If you need to sort arrays or modify values, you'll need to use a different tool or write custom code.

Related Tools

All Tools

See all available tools