Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

jsonschema - How to reference schema of json which is top level array

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...