I want to make a schema of json file.It's for an array of products.

The json schema is similar as below:

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product set",
"type": "array",
"items": {
    "title": "Product",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "number"
        },
        "name": {
            "type": "string"
        },
        "price": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true
        },
        "tags": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
        },
        "dimensions": {
            "type": "object",
            "properties": {
                "length": {"type": "number"},
                "width": {"type": "number"},
                "height": {"type": "number"}
            },
            "required": ["length", "width", "height"]
        },
        "warehouseLocation": {
            "description": "Coordinates of the warehouse with the product",
            "$ref": "http://json-schema.org/geo"
        }
    },
    "required": ["id", "name", "price"]
}
}

The array should at least one item in it. How can I define the minimum of the array?

Do I need to add the minimun defination?

推荐答案

I suppose no, at least looking to working draft the minimum is applied only for numeric values, not arrays.

5.1. Validation keywords for numeric instances (number and integer)
...
5.1.3. minimum and exclusiveMinimum

So you should be good with min/maxItems for arrays.

Json相关问答推荐

如果主对象中已存在属性,则不应在Jolt中引用次对象

Powershell ConvertFrom-Json 意外地从包含字符串的单个项目数组生成字符串而不是对象数组

使用 jolt 变换压平具有公共列 JSON 的复杂嵌套

Jolt - 如何比较 if else 条件的两个值

如何对未知/变量键的字典进行编码?

JOLT分裂和数组数据

Rust实现:高效解析任意大小的JSON数组

jq :遍历 json 并在键存在时检索集合

如何使用 SQL Server 将 json 存储为字符串的列分解/规范化为行和列?

添加到数组时出错:找不到Add的重载和参数计数:1

通过 xslt 将内部 json 转换为 xml 时遇到问题

使用 Jolt 变换将平面 json 转换为具有多个数组的嵌套 Json

使用 jq 同时迭代数组

如何在 Django 的模板语言中获取 json 键和值?

现代浏览器一次可以处理多少个 HTML 元素?

Spring MVC控制器中的JSON参数

将 JSON 对象推送到 localStorage 中的数组

PostgreSQL 中的 JSON 模式验证?

使用 Codable 序列化为 JSON 时的 Swift 字符串转义

将 JsonArray 添加到 JsonObject