我有一个json模式:-

{
    "type": "object",
    "properties": {
        "campaignType": {
            "type": "string",
            "enum": [
                "export"
            ]
        },
        "clientid": {
            "type": "integer",
            "minimum": 1
        },
        "select": {
            "type": "object",
            "minProperties": 1,
            "anyOf": [
                {
                    "required": [
                        "list"
                    ]
                },
                {
                    "required": [
                        "segment"
                    ]
                }
            ],
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                },
                "segment": {
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                }
            }
        },
        "attributes": {
            "type": "array",
            "minItems": 2,
            "items": { 
                "type": "string",
                "contains": ["fk", "uid"]
            }
        }
    },
    "required": [
        "campaignType",
        "clientid",
        "select",
        "attributes"
    ]
}

在这里,我想让属性字段的值"fk"、"uid"固定,并且必须允许其他字段值带有"fk"和"uid".

从json解组属性时出错:从json解组项目时出错:json:无法将对象解组为[]*jsonschema类型的Go值.架构

推荐答案

架构中的值contains必须是架构:

keyword contains error message

根据您的问题,可以将"属性"模式更改为:

"attributes": {
  "type": "array",
  "minItems": 2,
  "items": [ { "const": "fk" }, { "const": "uid" } ],
  "additionalItems": {
    "type": "string"
  }
}

Json相关问答推荐

抓取低于w jolt的对象级别

如何在对象投影(*)上应用滤镜投影([?port==`eth1`])?

在ConvertFrom-Json之后需要从PowerShell对象中获取数据

(Kotlin)com.google.gson.internal.LinkedTreeMap无法转换为com.example.phonetest2.model.HallData

JOLT转换以基于对象属性过滤JSON数组

当由.sh脚本执行时,AWS查询字符串不会提取任何数据

在这种情况下我如何实现 UnmarshalJSON 并且只为一个接口字段定义特殊行为?

JQ 中的样本标准偏差

如何从 JSON 中获取数据并通过 vb6 在网格中显示

使用 jq 同时迭代数组

为什么JsonConvert反序列化对象以int但不长失败

PowerShell - 如何迭代 PSCustomObject 嵌套对象?

从ruby中的json获取特定的键值

在 JSON API Wordpress 上启用 CORS

在 JSON 字符串中react i18n 换行符

Jackson Scala 模块的小例子?

Jsonpath 与 Jackson 或 Gson

Swift :将 struct 转换为 JSON?

未调用 npm package.json 脚本

如何从 JSON 响应中提取单个值?