How to reference schema of json which is top level array

↘锁芯ラ 提交于 2019-12-17 17:16:29

问题


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:

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

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.

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


回答1:


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

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

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

$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.

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



来源:https://stackoverflow.com/questions/57930439/how-to-reference-schema-of-json-which-is-top-level-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!