uniqueItems : Boolean
uniqueItems
BooleanIf this keyword is set to the boolean value true
, the instance validates successfully if all of its elements are unique.
Value |
This keyword must be set to a boolean value
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
---|---|
Kind | Assertion |
Applies To | Array |
Base Dialect | Draft 7 |
Changed In | None |
Introduced In | Draft 2 |
Vocabulary | Validation |
Specification | https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.6.4.5 |
Metaschema | http://json-schema.org/draft-07/schema# |
Official Tests | draft7/uniqueItems.json |
Default |
false
|
Annotation | None |
Affected By | None |
Affects | None |
Also See |
|
When set to true
, the uniqueItems
keyword restricts array instances to
items that only occur once in the array. Note that empty arrays and arrays that
consist of a single item satisfy uniqueness by definition.
Common Pitfall
Keep in mind that depending on the size and complexity of arrays, this keyword may introduce significant validation overhead. The paper JSON: data model, query languages and schema specification also noted how the presence of this keyword can negatively impact satisfiability analysis of schemas.
Remember that JSON Schema is a constraint-driven language.
Therefore, non-array instances successfully validate against this
keyword. If needed, make use of the type
keyword to constraint
the accepted type accordingly.
Examples
{
"$schema": "http://json-schema.org/draft-07/schema#",
"uniqueItems": true
}
[ 1, "hello", true, { "name": "John" } ]
[ { "name": "John" }, 1, "hello", true, { "name": "John" } ]
[]
"Hello World"
{
"$schema": "http://json-schema.org/draft-07/schema#",
"uniqueItems": false
}
[ 1, "hello", true, { "name": "John" } ]
[ { "name": "John" }, 1, "hello", true, { "name": "John" } ]
[]
"Hello World"