json-schema-spec icon indicating copy to clipboard operation
json-schema-spec copied to clipboard

Json schema array define ordering

Open Willem-J-an opened this issue 3 years ago • 3 comments

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.

Willem-J-an avatar Mar 16 '22 15:03 Willem-J-an

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.

awwright avatar Mar 16 '22 16:03 awwright

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).

karenetheridge avatar Mar 16 '22 17:03 karenetheridge

Is this related? https://github.com/json-schema-org/json-schema-vocabularies/issues/21

vcschapp avatar Feb 17 '23 23:02 vcschapp