因此,如果我有一个对象,我们称它为Person,例如:
{
"email": "[email protected]",
"first"" "foo",
"last": "bar"
}
此Person对象都可以使用JSON Schema很好地验证。问题是当其中的多个排列成字典时,其中电子邮件字段用作键,而对象是值。例如:
{
"[email protected]": {
"email": "[email protected]",
"first"" "foo",
"last": "bar"
},
"[email protected]": {
"email": "[email protected]",
"first": "Bob",
"last": "Bobton"
},
"[email protected]": {
"email": "[email protected]",
"first": "Deb",
"last": "Debbington"
}
}
这是一种结构化数据的常用方法。除了对Person值的验证(可以通过JSON Schema很好地处理)之外,还有许多对字典有用的验证:
是否可以使用JSON模式实现这些字典验证?
前两个要求,是的。您可以使用patternProperties
。
您要问的其他两个不能使用JSON模式。抱歉。
我的期望是您从API以第一种形式接收数据,进行验证,然后将reduce映射到所需的结构。