为什么布尔人有效的JSON模式?
我正在看json schema的 meta schemas ,并根据>
>核心/验证方言meta-schema
json true
和false
是有效的JSON Schemas。这是什么意思?
您会看到他们正确验证在这里。
I'm looking at JSON schema's meta schemas and according to the Core/Validation Dialect meta-schema
the JSON true
and false
are valid JSON schemas. What is the point of this?
You can see that they validate properly here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
的确,一个布尔式架构的全部内容并不是很有用,除了作为占位符(“将来,我们将具有更定义的数据结构;与此同时,所有值都是可以接受的”)。但是模式也可以包含模式,然后我们可以开始表达更有意义的事情。
考虑这样描述数据:
我们将以这样的方式定义JSON架构:
如您所见,在“属性”和“额外的Properties”关键字下,我们有几个子查玛。某些亚schemas包含更多关键字(在这种情况下为“类型”),但是某些亚种只是普通的旧布尔值。他们传达了一些意义:“这种情况总是有效的”或“这种情况总是无效的”。
It's true that a boolean schema, in its entirety, is not terribly useful, except perhaps as a placeholder ("in the future, we will have a more defined data structure; in the meantime, all values are acceptable"). But schemas can also contain schemas, and then we can start to express more meaningful things.
Consider describing data thusly:
We would define the JSON schema like this:
Now, as you can see, under the "properties" and "additionalProperties" keywords we have several subschemas. Some of the subschemas contain more keywords ("type" in this case), but some of the subschemas are just plain old booleans. They're conveying something of meaning: "this condition is always valid" or "this condition is always invalid".