Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想通过 json 模式验证 json 输入。正面案例适用于预期的对象和属性。但我想验证额外的对象,即模式中未提及的参数。
如果在 json 中检测到垃圾数据,则基本上验证失败
如果您只想在 JSON 对象中拥有一组属性并拒绝其他属性:
properties
patternProperties
定义additionalProperties为false:
additionalProperties
false
{ "type": "object", "properties": { "p": {}, "q": {} }, "additionalProperties": false }
将只允许属性p并存q在于对象实例中。
p
q