我使用的是json模式,希望只允许该文件中声明的属性通过验证.例如,如果用户在json对象中传递一个"name"属性,它将使该模式失败,因为"name"在这里没有作为属性列出.

Is there some function similar to "required" that will only allow the listed properties to pass?

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Accounting Resource - Add Item",
"type": "object",
"properties": {
    "itemNumber": {
        "type":"string",
        "minimum": 3
    },
    "title": {
        "type":"string",
        "minimum": 5
    },
    "description": {
        "type":"string",
        "minimum": 5
    }
},
"required": [
    "itemNumber",
    "title",
    "description"
]
}

推荐答案

I believe what you need to do to achieve this is set additionalProperties to false. See the specification here

Json相关问答推荐

使用JSONata将具有相同键的字典合并

按照对象键的值对PostgreSQL JSONB对象进行排序'

Golang JSON Date Tim.Date()测试请求

Vega-Lite时钟(使用Vega-Lite中的计时器)

JOLT转换以根据条件删除json对象

使用 JOLT 将日期格式转换为 JSON

jq json - 按键名 Select

是否可以在有条件的情况下将 json 对象转换为 JOLT 中的数组?

JBuilder中未定义的局部变量或方法json

Django - 异常处理最佳实践和发送自定义错误消息

JSON.stringify 不会转义?

C#扁平化json struct

如何向(JSON)对象的原型添加方法?

使用 JSON.Net 的 C# 到 JSON 序列化

与classic 规范化表相比,postgres JSON 索引是否足够高效?

Spring restTemplate 获取原始 json 字符串

字符串格式 JSON 字符串给出 KeyError

MVC JsonResult camelCase 序列化

如何使用 SwiftyJSON 遍历 JSON?

Laravel 5 控制器将 JSON 整数作为字符串发送