This is a type of schema that validates your object. There are many different things you can do with JSON object validation. To be able to define schema for an object, you have set type to object and add properties and their schemas to `properties.

{  
	"type": "object",  
	"properties": {  
		"name": {  
			"type": "string"  
		}  
	}  
}  

Pattern Properties

They allow you to create schema for the name of the property. A pattern can be created with Regex and your property name will have to match it. Otherwise, it will err.

Example

{  
  "type":"object",  
  "patternProperties": {  
    "^DEPT-[0-9]{3}$": {  
      "type": "string"  
    }  
  }  
}  
  
/*   
JSON Example  
{  
	"DEPT-001": "HR"  
}  
*/  

Additional Properties

By default, when validating JSON against your schema, it will not error when there are additional properties in it. To prevent this from happening, you can use additionalProperties setting and set it to false.

{  
  "type": "object",  
  "properties": {  
    "name": {...},  
    "age": {...}  
  },  
  "additionalProperties": false  
}  

However, if you want to allow additional properties in your JSON schema, but want to verify of what type they should be, you can define what kind of type additional properties should be.

{  
  "type": "object",  
  "properties": {  
    "name": {...},  
    "age": {...}  
  },  
  "additionalProperties": {  
    "type": "string"  
  }  
}  

Number of Properties Constraint

You can add constraints to the amount of properties you can add to your object. This is useful when, for example, you create a reusable JSON schema for address and you have a range of properties that should be allowed in that particular object.

{  
  "type": "object",  
  "minProperties": 2,  
  "maxProperties": 5  
}  

Property Names

If you want to restrict the way of creating your property names in your JSON, you can add validation to it.

{  
  "type": "object",  
  "minProperties": 2,  
  "propertyNames": {  
    "pattern": "^[A-Z]+$",  
    "minLength": 3  
  },  
  "additionalProperties": {  
    "type": [  
      "string",  
      "integer"  
    ]  
  }  
}