我正在使用https://www.npmjs.com/package/jsonschema验证看起来像这样的传入JSON数组
{
"source": "app",
"data": [
{
"customerId": "1",
"Address": {
"number": "1",
"street": "st1"
}
},
{
"customerId": "2",
"Address": {
"number": "2",
"street": "st1"
}
},
{
"customerId": "3",
"Address": {
"number": "3"
}
}
]
}
在此数据中,第三项customerId: 3
无效,因为它缺少street
中的address
字段。有什么办法让我找出data
中已过滤的有效项目?
我尝试了errors.instance,但是例如最多只能给Address
"Address": {
"number": "3"
}
理想情况下,我想要的是以下
{
"source": "app",
"data": [
{
"customerId": "1",
"Address": {
"number": "1",
"street": "st1"
}
},
{
"customerId": "2",
"Address": {
"number": "2",
"street": "st1"
}
}
]
}