简单地说,不。
有一个叫做JSON Schema的东西,它是一个2013年到期的互联网草案。互联网草案是产生Internet Standard的第一阶段。在official site 上查看更多信息,因为它似乎仍在积极开发中,尽管它(据我所知)并未广泛使用。
架构示例:
{
"$schema": "http://json-schema.org/schema#",
"title": "Product",
"type": "object",
"required": ["id", "name", "price"],
"properties": {
"id": {
"type": "number",
"description": "Product identifier"
},
"name": {
"type": "string",
"description": "Name of the product"
},
"price": {
"type": "number",
"minimum": 0
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"stock": {
"type": "object",
"properties": {
"warehouse": {
"type": "number"
},
"retail": {
"type": "number"
}
}
}
}
}
将验证此示例 JSON:
{
"id": 1,
"name": "Foo",
"price": 123,
"tags": [
"Bar",
"Eek"
],
"stock": {
"warehouse": 300,
"retail": 20
}
}
编辑 因为它们都(或多或少)做同样的事情并且具有非常相似的语法,所以性能应该是最大的关注点。请参阅 here 以比较 JSON 验证器的性能 - 获胜者是 ajv,这是我个人使用的原因。