JSON schema 是否有任何标准或约定来将实例文档与其所遵循的模式相关联?

Does JSON schema have any standards or conventions for associating an instance document with the schema to which it conforms?

我是 Json 架构的新手,但过去曾使用 xsd 的(xml 架构)进行了大量工作。
使用 xml 模式可以在 xml 文档中标记元素 使用 'schemaLocation' 属性。此属性可由验证 xml 使用 解析器验证元素的内容和结构是否符合其关联的 模式。在 xml 你做这样的事情:

<animal 
    xsi:schemaLocation="
        http://www.zippy.com 
        http://foo.bar.com/animal.xsd">
    type="dog"
    name="rover"/>

我想知道:在 JSON 架构中是否有一些标准的方法可以做到这一点?
我在规范中找不到任何内容或 我完成的教程。
我希望可能会有这样的事情:

{
    "schema": "http://foo.bar.com/animal.schema.json",

    "animal": {
        "type": "dog",
        "name": "rover",
    }
}

我的目标是让我的 REST 服务 returns 包含注释的每个 JSON 文档 (一个属性 "schema",或类似的东西)指向模式 验证该特定实例...然后我可以选择在“验证”中启动该服务 模式”,其中它会自动验证出站响应以确保它们符合模式。

非常感谢任何建议。

JSON 文档没有标准方法来识别描述它的模式。 JSON 架构的设计目标之一是它不会对正在验证的 JSON 文档的结构施加任何影响。

但是,JSON 架构确实定义了一种方法,可以在 HTTP 响应的上下文中将 link 一个 JSON 架构添加到文档。您可以使用 describedby Link header 来识别架构。

HTTP/1.1 200 OK
Content-Type: application/json
Link: <http://foo.bar.com/animal.schema.json>; rel="describedby"

{
    "animal": {
        "type": "dog",
        "name": "rover"
    }
}

http://json-schema.org/latest/json-schema-core.html#rfc.section.10.1