您应该如何引用JSON对象符合的JSON模式? [英] How should you reference the JSON schema that a JSON object conforms to?

查看:75
本文介绍了您应该如何引用JSON对象符合的JSON模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有另一个与我在这里询问的问题类似的问题(如何引用作为顶级数组的json模式),但我对此问题的细微变化.

There was another question similar to the one I am asking here (Can you specify the schema URI on a JSON document that conforms to a JSON schema?) that was tagged as a duplicate of (How to reference schema of json which is top level array), but I have nuanced variation of the question.

虽然JSON模式定义中似乎没有任何内容( https://json-schema.org/),是否存在人们遵循的最佳实践,以便在JSON对象/文档中指示其符合(或应该符合)哪种JSON模式?

While it appears that there isn't anything in the JSON schema definition (https://json-schema.org/), is there a best practice that people follow in regards to indicating within a JSON object/document which JSON schema it conforms to (or is supposed to conform to)?

在JSON对象/文档中使用$ schema标记引用架构是否错误?似乎引用它所遵循的架构也是版本化" JSON对象/文档的一种好方法.

Would it be wrong to reference the schema using the $schema tag within a JSON object/document? It seems like referencing the schema it conforms to would also be a be a good way to "version" JSON objects/documents.

推荐答案

我非常怀疑对此问题是否存在可接受的"答案.

I very much doubt there is an "acceptable" answer to this question.

没有什么可以阻止您将$ schema属性用作您个人约定的一部分.

There's nothing to stop you from using the $schema attribute as part of your own personal convention.

对此有一些现实的先例.一些Azure快速入门模板使用$ schema引用它们遵循的JSON模式,例如:标记T 进行评论)

There is some real-world precedent to this. Some Azure quickstart templates use $schema to reference the JSON Schema they adhere to eg: https://github.com/Azure/azure-quickstart-templates/blob/master/101-azure-bastion/azuredeploy.parameters.json (Thanks to Mark T for his comment)

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "bastion-host-name": {
        "value": "GEN-UNIQUE-8"
    },
      "location": {
        "value": "southcentralus"
    }
  }
}

但是,由于缺乏官方指导,我们也许应该接受 schema-instance (来自XSD)的概念不太适合像jsonschema这样的轻量级定义语言.

However, with a lack of official guidance we should perhaps just accept that the concept of schema-instance (as taken from XSD) is not a good fit for a lightweight definition language such as jsonschema.

我很想了解您的用例,其中需要将JSON实例与其架构明确链接.

I would be interested to understand your use-case where linking JSON instances explicitly with their schemas is a requirement.

这篇关于您应该如何引用JSON对象符合的JSON模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆