Unique Array Items

Let's use the example from our previous lesson. We have an array of phone numbers. We want to make sure that the phone numbers are unique.

1{
2  "name": "John Doe",
3  "age": 25,
4  "phones": ["123-456-7890", "987-654-3210"]
5}

uniqueItems Keyword

To ensure that the items in an array are unique, you can use the uniqueItems keyword.

Example:

1{
2  "type": "array",
3  "items": {...},
4  "uniqueItems": true
5}

Now, try to modify the phones property in the schema given on the side editor to ensure that the phone numbers are unique.

Loading...
Output
Please click the button or use
Shift+Enter
to view the output