sort

The sort parameter specifies how the results will be sorted on the response, and which properties will be used for sorting.

sort can be specified as either a single value (a property name), an array of values (when sorting by multiple properties), or an object.

By default, results will be ordered in ascending order (lowest to highest). The order can be specified using the object variant.

Sort Using a Single Property

The results can be sorted by the value of single property:

"sort": "name"

Sort Using Multiple Properties

The results can be sorted by the value of multiple properties, in the specified order:

"sort": ["lastname", "name"]

Sort using an array of Objects

The results can be sorted by the value of multiple properties, in the specified order:

"sort": [
    "lastname",
    { "key": "name", "order": "descending"},
    { "key": "age",  "order": "ascending"},
]

Sort Examples

[ {
    "FindImage": {
        "constraints" : {
            "year_captured": [ ">=", 1970 ]
        },
        "sort": "year_captured",
        "results": {
            "list": ["year_caputured"]
        }
    }
}]

# Response:

[ {
    "FindImage": {
        "entities": [
            {
                "year_captured": 1970
            },
            {
                "year_captured": 1980
            },
            {
                "year_captured": 1990
            }
        ]
    }
}]
[ {
    "FindImage": {
        "constraints" : {
            "year_captured": [ "<=", 1970 ]
        },
        "sort": ["year_captured", "artist"],
        "results": {
            "list": ["year_caputured", "artist", "event"]
        }
    }
}]

# Response:

[ {
    "FindImage": {
        "entities": [
            {
                "year_captured": 1970,
                "artist": "Alice",
                "event": "January Festival"
            },
            {
                "year_captured": 1980,
                "artist": "Alice",
                "event": "April Festival"
            },
            {
                "year_captured": 1980,
                "artist": "Bob",
                "event": "April Festival"
            }
        ]
    }
}]
[ {
    "FindImage": {
        "constraints" : {
            "year_captured": [ "<=", 1970 ]
        },
        "sort": [
            { "key": "year_captured", "order": "descending"}
            { "key": "artist",        "order": "descending"}
        ],
        "results": {
            "list": ["year_caputured", "artist", "event"]
        }
    }
}]

# Response:

[ {
    "FindImage": {
        "entities": [
            {
                "year_captured": 1980,
                "artist": "Bob",
                "event": "April Festival"
            },
            {
                "year_captured": 1980,
                "artist": "Alice",
                "event": "April Festival"
            },
            {
                "year_captured": 1970,
                "artist": "Alice",
                "event": "January Festival"
            }
        ]
    }
}]