typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
71.91k stars 6.93k forks source link

sorting by array size #707

Open sofientouati opened 6 years ago

sofientouati commented 6 years ago

hi I want to sort my response by array size for example like this :

        {
            "id": 7,
            "name": "Scimitar",
            "games": [
                128,
                5152,
                2438
            ]
        },
        {
            "id": 4,
            "name": "GoldSrc",
            "games": [
                231,
                6738,
                232,
                2549,
                7551,
                8319,
                9073,
                7589,
                241,
                55025,
                23759,
                1335
            ]
        },
        {
            "id": 5,
            "name": "NeL",
            "games": [
                6742
            ]
        }

        }]}

to something like this :

        {
            "id": 4,
            "name": "GoldSrc",
            "games": [
                231,
                6738,
                232,
                2549,
                7551,
                8319,
                9073,
                7589,
                241,
                55025,
                23759,
                1335
            ]
        },
        {
            "id": 7,
            "name": "Scimitar",
            "games": [
                128,
                5152,
                2438
            ]
        },
        {
            "id": 5,
            "name": "NeL",
            "games": [
                6742
            ]
        }]}`
Nilegfx commented 6 years ago

use _sort as follow:

GET /users?_sort=games.length&_order=desc