You can add various validation rules to your arrays in JSON schema. It is very useful for restricting the number of items you can save in it, the pattern that items in an array should follow etc. The most basic schema for arrays looks like this.

{  
	"type": "array",  
	"items": {  
		"type": "string"  
	}  
}  

Length

If you want to restrict how many items can be stored in an array, you can do it with JSON schema. To be able to set minimum length, you use minLength property and set a value as a number. If you want to set the maximum length, you can use maxLength and set a number.

{  
	"type": "array",  
	"items": {...},  
	"minLength": 1,  
	"maxLength": 5  
}  

Pattern

If you want to have a control over the shape of the values in your array, you can do it by setting pattern value in items. pattern takes Regex.

{  
	"type": "array",  
	"items": {  
		"type": "string",  
		"pattern": "^\\d{3}-\\d{3}-\\d{4}$"  
	}  
}  

Unique Items

Sometimes, you may want to only allow unique values in your array. You can do it by setting uniqueItems property to true.

{  
	"type": "array",  
	"uniqueItems": true,  
	"items": {  
		"type":"string"  
	}  
}  

Tuple

You can add schema to arrays and verify them as a tuple. You can do it by adding prefixItems property and providing types in an array in an order you want them to be validated in your tuple/array.

{  
	"type": "array",  
	"prefixItems": [  
		{"type": "integer"}  
		{"type": "string"}  
		{"type": "integer"}  
	]  
}  

By default, schema for tuples will break if you add additional properties to it. If you want to allow additional properties, you can set items to false and add a type in prefixItems at the end of the list that you want to allow as an additional property

{  
	"type": "array",  
	"items": false,  
	"prefixItems": {  
		{"type": "integer"},  
		{"type": "string"}  
	}  
}  

Enums

You can add enums to restrict the items you can add to your array.

{  
	"type": "array",  
	"items: {  
		"enum": ["HR", "Devs", "Finance"]  
	}  
}  

Ensuring Array Content

It is used to ensure that array contains at least one element that matches subschema defined in contains keyword.

{  
	"type": "array",  
	"contains": {  
		"type": "number",  
		"maximum": 10  
	}  
}  

MinContains & MaxContains

You can use maxContains and minContains to ensure that items in an array have a min and max amount of items inside.

{  
	"type": "array",  
	"contais": {  
		"type": "number",  
		"minimum": 8,  
		"maximum": 12  
	},  
	"minContains": 2  
}