> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alumio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Object: Sort keys

> Sorts the keys of an object based on the provided sort method and direction.

export const FormField = ({property, label, required = false, diType, uiPatterns, children}) => {
  const patterns = Array.isArray(uiPatterns) ? uiPatterns : uiPatterns ? [uiPatterns] : [];
  return <div style={{
    margin: '1.5rem 0'
  }}>
      <div style={{
    display: 'flex',
    alignItems: 'baseline',
    flexWrap: 'wrap',
    gap: '0.5rem',
    marginBottom: '0.25rem'
  }}>
        <strong>{label}</strong>
        <span style={{
    fontSize: '0.7rem',
    fontWeight: 600,
    textTransform: 'uppercase',
    letterSpacing: '0.04em',
    color: required ? '#6241f5' : '#6b7280'
  }}>
          {required ? 'Required' : 'Optional'}
        </span>
      </div>

      <div>{children}</div>

      {diType || patterns.length > 0 ? <p style={{
    fontSize: '0.85rem',
    color: '#6b7280',
    marginBottom: 0
  }}>
          {diType ? <>
              See the <a href={`/references/${diType}`}>{diType}</a> reference.{' '}
            </> : null}
          {patterns.length > 0 ? <>
              Accepts a <a href={`/documentation/placeholders-and-patterns/patterns#${patterns[0]}`}>pattern</a>.
            </> : null}
        </p> : null}
    </div>;
};

Sorts the keys of an object based on the provided sort method and direction. Only the order of the fields changes; every value stays attached to its own key and nothing is added or removed. Use this when a target system expects fields in a predictable order, or simply to make your output easier to read. You can sort alphabetically up or down, or put specific keys first in an order you choose.

This documentation describes: [Schema](/schemas/mapper/object-sort-keys)

## Fields

<FormField property="method" label="method" required>
  How the keys are sorted. Choose one of:

  * **Ascending** sorts the keys from A to Z (and lowest to highest for numbers).
  * **Descending** sorts the keys from Z to A (and highest to lowest for numbers).
  * **Manual** lets you list the keys in the exact order you want them.
</FormField>

<FormField property="flag" label="Key treatment method">
  Shown when you pick Ascending or Descending. It controls how the key names are compared while sorting:

  * **Automatic** lets the system decide based on the keys (the default).
  * **Treat keys as numeric** compares keys as numbers, so `2` comes before `10`.
  * **Treat keys as string** compares keys character by character, so `10` comes before `2`.
</FormField>

<FormField property="keys" label="Keys">
  Shown when you pick Manual. The list of key names in the order you want them to appear. The keys you list are placed first, in this order; any remaining keys in the object follow in their original order. A key you list that is not present in the input is simply skipped.
</FormField>

## Sample data

| Field  | Value       |
| ------ | ----------- |
| method | `Ascending` |

Input:

```json theme={null}
{
    "address": { "zip": "1011 AB", "city": "Amsterdam", "country": "NL", "street": "Keizersgracht 1" }
}
```

Output:

```json theme={null}
{
    "address": { "city": "Amsterdam", "country": "NL", "street": "Keizersgracht 1", "zip": "1011 AB" }
}
```

```json Configuration theme={null}
{
  "prototype": "object-sort-keys",
  "parameters": {
    "method": "ksort"
  }
}
```
