如何引用作为顶级数组的json的架构 [英] How to reference schema of json which is top level array

查看:151
本文介绍了如何引用作为顶级数组的json的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含项目列表的JSON文件.存储在此文件中的唯一东西是作为数组的项目.例如:

I have a JSON file which contains a list of items. The only thing stored in this file is the items as a array. e.g:

[
    {...},
    {...},
    {...},
]

我想为此定义一个模式文件.这似乎很好,因为可以将初始类型设置为数组,并且我可以将项目定义为类型.但我想在项目json文件中引用架构.不幸的是,它不是对象,因此我无法添加"$schema"键.我当然可以使json一个对象只有一个具有数组值的键,但这似乎不是一个好的设计.

I want to define a schema file for this. This seems fine as the initial type can be set to array and I can define items as a type. But I want to reference the schema in the item json file. Unfortunately it is not an object so I cannot add the "$schema" key. I could of course make the json a object with only one key that has the array value but this doesn't seem to be good design.

模式系统似乎存在某些设计错误,还是不支持顶级数组json?

Does the schema system seems to have some design fault or is top level array json unsupported?

推荐答案

我认为您可能已经假定根据JSON Schema,将$schema放入JSON数据中具有任何意义.

I think you may have assumed that putting $schema in your JSON data has any meaning according to JSON Schema.

但是我想引用项目json文件中的架构.

But I want to reference the schema in the item json file.

赋予它的任何含义都不来自JSON Schema规范.

Any meaning given to it is not from the JSON Schema specification.

$schema在JSON模式中使用.该规范未定义任何方法来允许JSON文档识别为应符合架构的方法.

$schema is used in JSON Schemas. The specification does not define any method to allow the JSON document to identify as one which should conform to a schema.

有一种方法可以使用HTTP标头,但仅此而已.

There is a method that utilities HTTP headers, but that is all.

这篇关于如何引用作为顶级数组的json的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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