给定以下JSON架构,是否可以指示"name"属性应该是唯一的(即,"element"数组中不应该有两个具有相同"name"的项.

{
  "root": {
    "type": "object",
    "properties": {
      "elements": {
        "type": "array",
        "minItems": 1,
        "items": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "title": "Element Name",
              "minLength": 3,
            },
            "url": {
              "type": "string",
              "title": "Some URL"
            }
          }
        }
      }
    }
  }
}

I tried to use the uniqueItems keyword but it seems it was designed for simple lists of values.

推荐答案

No, it is not possible. From the docs, json-schema: ...a JSON based format for defining the structure of JSON data.

It is quite limited for making data values validation because it is not the purpose of the standard. Many people have asked this before because it is common to request a kind of "unique Id" feature. Unfortunately for those who need it, json-schema does not provides you with that.

So if you want to ensure uniqueness your only option is to have "name" as property keys instead of property values.

Json相关问答推荐

Vega-Lite:文本笔画在外部

使用单元和非单元版本反序列化Rust中的枚举,而无需编写自定义反序列化程序

Python将Pandas转换为嵌套的JSON

使用Jolt v.0.1.1向每个json元素添加一个键-值对

Pandas 对REST API的自定义响应

如何将复杂的 JSON 反序列化为 Rust 类型?

JSONPath:查找子项目条件在字符串列表中的项目

如何从字符串中创建一个逗号分隔的列表,由 API 中的 JSON 对象内的编号空格分隔?

如何将该 JSON 解析为 Kotlin 类?

jq搜索特定字符串并输出对应的父值

如何用 Xidel 正确读取这个 JSON 文件?

使用 jq 同时迭代数组

如何对使用转换器的 Grails 服务进行单元测试?

如何将任意 json 对象发布到 webapi

在 bash 中将 CSV 转换为 JSON

以 unicode 将 pandas DataFrame 写入 JSON

如何在 MVC4 中将 Json 字符串输出为 JsonResult?

JSON 和 BSON 哪个更轻量级?

如何使用 Jackson 的 objectMapper 反序列化接口字段?

如何对 Javascript 对象进行排序,或将其转换为数组?