具有未知属性名称的JSON模式 [英] JSON Schema with unknown property names

查看:60
本文介绍了具有未知属性名称的JSON模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在对象数组中创建一个具有未知属性名称的JSON模式. 一个很好的例子是网页的元数据:

I want to have a JSON Schema with unknown property names in an array of objects. A good example is the meta-data of a web page:

      "meta": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "unknown-attribute-1": {
              "type": "string"
            },
            "unknown-attribute-2": {
              "type": "string"
            },
            ...
          }
        }
      }

请问有没有其他想法或达成相同想法的其他方法?

Any ideas please, or other way to reach the same?

推荐答案

使用patternProperties代替properties.在下面的示例中,模式匹配正则表达式.*接受任何属性名称,并且我仅允许使用"additionalProperties": false来允许stringnull的类型.

Use patternProperties instead of properties. In the example below, the pattern match regex .* accepts any property name and I am allowing types of string or null only by using "additionalProperties": false.

  "patternProperties": {
    "^.*$": {
      "anyOf": [
        {"type": "string"},
        {"type": "null"}
      ]
    }
  },
  "additionalProperties": false

这篇关于具有未知属性名称的JSON模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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