# Sort API
> Sort a list — or an array of objects by one of its keys — the way you actually want. Natural (alphanumeric) ordering puts file2 before file10 and v1.9 before v1.10, the way humans expect; alphabetical, numeric and by-length orderings are also built in, each ascending or descending, with an optional case-insensitive mode. Items can be plain strings (comma- or newline-separated) or a JSON array; for objects, give the property to sort by and rows missing it go last. Perfect for file and version lists, leaderboards and tables, tidying user input and any UI that shows sorted data. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. Distinct from set operations and CSV tooling.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/sort-api/..."
```

## Pricing
- **Free** (Free) — 1,165 calls/Mo, 2 req/s
- **Starter** ($2/Mo) — 10,050 calls/Mo, 8 req/s
- **Pro** ($22/Mo) — 151,500 calls/Mo, 20 req/s
- **Mega** ($60/Mo) — 800,000 calls/Mo, 50 req/s

## Endpoints

### Sort

#### `GET /v1/sort` — Sort a list

**Parameters:**
- `list` (query, required, string) — JSON array or comma/newline list Example: `file10,file2,file1`
- `mode` (query, optional, string) — natural|alphabetical|numeric|length (default natural) Example: `natural`
- `order` (query, optional, string) — asc|desc (default asc) Example: `asc`
- `case_insensitive` (query, optional, string) — true/false

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/sort-api/v1/sort?list=file10%2Cfile2%2Cfile1&mode=natural&order=asc"
```

**Response:**
```json
{
    "data": {
        "mode": "natural",
        "count": 3,
        "order": "asc",
        "result": [
            "file1",
            "file2",
            "file10"
        ],
        "case_insensitive": false
    },
    "meta": {
        "timestamp": "2026-06-03T01:09:39.445Z",
        "request_id": "f696708f-ae43-4bee-8840-c3eb9d429055"
    },
    "status": "ok",
    "message": "Sort a list",
    "success": true
}
```

#### `GET /v1/sort-objects` — Sort objects by a key

**Parameters:**
- `json` (query, required, string) — Array of objects Example: `[{"name":"b","age":30},{"name":"a","age":5}]`
- `key` (query, required, string) — Property to sort by Example: `age`
- `mode` (query, optional, string) — natural|alphabetical|numeric|length (default natural) Example: `natural`
- `order` (query, optional, string) — asc|desc (default asc) Example: `asc`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/sort-api/v1/sort-objects?json=%5B%7B%22name%22%3A%22b%22%2C%22age%22%3A30%7D%2C%7B%22name%22%3A%22a%22%2C%22age%22%3A5%7D%5D&key=age&mode=natural&order=asc"
```

**Response:**
```json
{
    "data": {
        "key": "age",
        "mode": "natural",
        "count": 2,
        "order": "asc",
        "result": [
            {
                "age": 5,
                "name": "a"
            },
            {
                "age": 30,
                "name": "b"
            }
        ]
    },
    "meta": {
        "timestamp": "2026-06-03T01:09:39.542Z",
        "request_id": "c556ba07-8dee-4c3e-83ae-02cc925de772"
    },
    "status": "ok",
    "message": "Sort objects by a key",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/sort-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "name": "Sort API",
        "notes": "Natural sort uses the platform's Unicode collator with numeric ordering. Items missing the sort key are placed last. Nothing is stored.",
        "version": "v1",
        "endpoints": [
            {
                "path": "/v1/sort",
                "params": {
                    "list": "JSON array or comma/newline list (required)",
                    "mode": "natural|alphabetical|numeric|length (default natural)",
                    "order": "asc|desc",
                    "case_insensitive": "true/false"
                },
                "returns": "the sorted list"
            },
            {
                "path": "/v1/sort-objects",
                "params": {
                    "key": "property to sort by (required)",
                    "json": "array of objects (required)",
                    "mode": "default natural",
                    "order": "asc|desc"
                },
                "returns": "the sorted array of objects"
            },
            {
                "path": "/v1/meta",
                "params": [],
                "returns": "this document"
            }
        ],
        "description": "Sort a list — or an array of objects by a key — using natural (alphanumeric, so file2 comes before file10), alphabetical, numeric or by-length ordering, ascending or descending, with an optional case-insensitive mode. Pure local, no key."
    },
    "meta": {
        "timestamp": 
…(truncated, see openapi.json for full schema)
```


---
Marketplace page: https://www.oanor.com/api/sort-api
OpenAPI spec: https://www.oanor.com/api/sort-api/openapi.json
