使用JSON模式进行属性验证的唯一值 [英] Unique value for a property validation using json schema
本文介绍了使用JSON模式进行属性验证的唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JSON对象,如:
{
"result": [
{
"name" : "abc",
"email": "abc.test@mail.com"
},
{
"name": "def",
"email": "def.test@mail.com"
},
{
"name": "xyz",
"email": "abc.test@mail.com"
}
]
}
和模式:
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/object1607582431.json",
"title": "Root",
"type": "object",
"required": [
"result"
],
"properties": {
"result": {
"$id": "#root/result",
"title": "Result",
"type": "array",
"default": [],
"uniqueItems": true,
"items": {
"$id": "#root/result/items",
"title": "Items",
"type": "object",
"required": [
"name",
"email"
],
"properties": {
"name": {
"$id": "#root/result/items/name",
"title": "Name",
"type": "string"
},
"email": {
"$id": "#root/result/items/email",
"title": "Email",
"type": "string"
}
}
}
}
}
}
我正在寻找一个选项来检查email
的唯一性,而不管其名称如何.如何验证每个email
应该是唯一的?
解决方案
您不能.除了uniqueItems
之外,没有关键字可让您将一个特定的数据值与另一个特定的数据值进行比较.
I have a JSON object like:
{
"result": [
{
"name" : "abc",
"email": "abc.test@mail.com"
},
{
"name": "def",
"email": "def.test@mail.com"
},
{
"name": "xyz",
"email": "abc.test@mail.com"
}
]
}
and schema for this:
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://example.com/object1607582431.json",
"title": "Root",
"type": "object",
"required": [
"result"
],
"properties": {
"result": {
"$id": "#root/result",
"title": "Result",
"type": "array",
"default": [],
"uniqueItems": true,
"items": {
"$id": "#root/result/items",
"title": "Items",
"type": "object",
"required": [
"name",
"email"
],
"properties": {
"name": {
"$id": "#root/result/items/name",
"title": "Name",
"type": "string"
},
"email": {
"$id": "#root/result/items/email",
"title": "Email",
"type": "string"
}
}
}
}
}
}
I am looking for an option to check uniqueness for email
irrespective of name. How I can validate that every email
should be unique?
解决方案
You can't. There are no keywords that let you compare one particular data value against another, other than uniqueItems
, which compares an array element in toto against another.
这篇关于使用JSON模式进行属性验证的唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文