JSON schema draft4与JSON schema draft3的区别

19

JSON schema草案4中有哪些特性是IETF生产的JSON schema草案3中没有的?

2个回答

31

从变更日志中:

新增关键词

  • anyOf(至少匹配模式数组中的一个模式)
  • allOf(匹配模式数组中的所有模式)
  • oneOf(仅匹配模式数组中的一个模式)
  • not(不匹配该模式)
  • multipleOf(替换divisibleBy)
  • minProperties和maxProperties(对象实例中成员的最小和最大数目)
  • definitions(内嵌子模式的标准化容器)

已删除:

  • disallow
  • extends
  • divisbleBy

功能变更:

Type

  • 当值为数组时,不再允许模式作为元素。而且,该数组必须至少有一个元素。

之前


{
    "type": [ "string", { "other": "schema" } ]
}

现在


{
   "anyOf": [
       { "type": "string" },
       { "other": "schema" }
    ]
}

必需的

  • 之前,它是属性中子模式的一个属性。现在,它是第一层关键字,扮演相同的角色,并使用字符串数组作为参数。

之前


{
    "properties": {
        "p": {
            "type": "string",
            "required": true
        },
        "q": {
            "type": "string",
            "required": true
        }
    }
}

现在


{
    "properties": {
        "p": { "type": "string" },
        "q": { "type": "string" }
    },
    "required": [ "p", "q" ]
}

依赖项

  • 在属性依赖项中,不再允许使用单个字符串,只允许使用数组

之前


{
    "dependencies": { "a": "b" }
}

现在


{
    "dependencies": { "a": [ "b" ] }
}

谢谢你!我正在开发一个非常大的项目,其中json-schema非常重要。如果Json.Net决定从草案3转移到4,那将是有趣的时刻。 - PercivalMcGullicuddy

6
如果你对此更加深入了解,你可以查看IETF网站上两个草案之间的差异比较,链接如下:review a diff between the two drafts on the IETF site
然而,如果你只需要简要了解变更内容,Geraint Luff和Francis Galiegue在项目的github wiki上创建了一个变更日志页面,列出了变更、新增和移除的内容,链接如下:changelog page

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接