JSON validates optional parameter using schema

I want to check json input through json scheme. A positive case works for intended objects and properties. But I want to check for additional objects, parameters that are not mentioned in the circuit.

Basically, fails to check if junk data was detected in json

+4
source share
1 answer

If you want to have only a specific set of properties in JSON objects and refuse to others:

  • make sure you have the appropriate schema in properties and patternProperties ,
  • define additionalProperties - false :

     { "type": "object", "properties": { "p": {}, "q": {} }, "additionalProperties": false } 

will only allow p and q in instances of objects.

+9
source

All Articles