json-schema-spec
json-schema-spec copied to clipboard
Json schema array define ordering
When defining an array in a json schema, I would like to be able to define the items of the array to be in ascending/descending order.
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "array",
"additionalItems": false,
>>>>> "sort": "ascending",
"items": {
"type": "string"
}
Has this been considered, or could this be considered? In this case I need ordering of json primitives, but I have also seen a request for ordering of objects here.
This is interesting... this is not especially expensive to validate (it can consume unbounded memory, though not in the same complexity as "uniqueItems"), and if it's present, you can safely assume the array is describing an unordered set, and not an ordered list.
The biggest problem would be defining a sorting order for non-scalars and between types. IndexedDB defines a sorting order for JSON, which could be adopted.
I think I created an issue somewhere sketching out how a vocabulary might look that defined some keywords like "isSorted" for strings, and describing how string sorting semantics should work (because of Unicode, it's straightforward but not intuitive for those living in an ascii world).
Is this related? https://github.com/json-schema-org/json-schema-vocabularies/issues/21