JSON Schema中描述枚举可以通过以下方式实现: 定义枚举类型:在JSON Schema中,可以使用"enum"关键字来定义枚举类型,并在其中列出所有可能的取值。例如: 代码语言:txt 复制 { "type": "string", "enum": ["option1", "option2", "option3"] } 上述示例定义了一个字符串类型的枚举,它的取值可以
{ "type": "array", "items": [ { "type": "number" }, { "type": "string" }, { "type": "string", "enum": [ "Street", "Avenue", "Boulevard" ] }, { "type": "string", "enum": [ "NW", "NE", "SW", "SE" ] } ], "additionalItems": false } 1. 2. 3. 4. 5....
可以通过Json Schema内建的一些类型,对字符串的格式做规范,例如电子邮件、日期、域名等。 { "type" : "string", "format" : "date", } Json Schema支持的format包括"date", "time", "date-time", "email", "hostname"等。具体可以参考文档。 3.2 数值 Json Schema数值类型包括"number"和"integer"。numb...
"type": "string", "enum": ["Street", "Avenue", "Boulevard"] } }, "required": ["number", "street_name"] } "$schema"、$id、title、description这 4 个字段先不看。 "type": "object",说明这个 JSON 的类型,通常为 object 或 array properties 关键字指定这个object有三个属性 number,street_...
JSON Schema 还支持组合和条件关键字,允许定义多个规则的组合以及根据条件选择不同的验证规则。以下是一个简单的组合和条件的示例: { "type": "object", "properties": { "role": { "type": "string", "enum": ["admin", "user"] }, "adminDetails": { "type": "object", "required": ["adminCo...
JSON Schema 本身是一段 JSON 格式的数据,如下例所示: { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "name": { "type": "string" }, "email": { "type": "string" }, "age": { ...
"additionalProperties": false :json串只能出现schema定义的属性。 "additionalProperties":{"type":"string"} :json串能出现不在schema定义范围内的属性, 但属性的类型必须为string {"type": "object","properties": {"number": {"type": "number"},"name": {"type": "string"} ...
JSON数据②(JSON Schema): 代码语言:javascript 代码运行次数:0 运行 AI代码解释 { "type": "object", "properties": { "name": { "type": "string", "minLength": 4 }, "age": { "type": "integer", "minimum": 0, "maximum": 130 }, "gender": { "type": "string", "enum": [ "mal...
json schema是无限递归,为不同类型时有不同的描述关键字,顶级必须的type必须是object类型,且代表根目录 4.1 object类型 4.2 array类型 当type取值为array时,涉及的关键字:items、additionalItems、minItems、maxItems、uniqueItems、contains 4.3 integer和number类型 当type取值为integer或number时涉及的关键字:...
JSON Schema 本身也是 JSON,区别是 Schema 是一种 DSL (领域特定语言),也就是说它有自己特定的字段和结构。当我们将其导入 CUE 时,cue 命令行会识别并处理。我们会用 这里 的docker-compose 规范。你可以从 Schema Store 找到许多例子或者用一些你周围的例子。