问题
I'm using https://www.npmjs.com/package/jsonschema to validate an incoming JSON array that looks something like this
{
"source": "app",
"data": [
{
"customerId": "1",
"Address": {
"number": "1",
"street": "st1"
}
},
{
"customerId": "2",
"Address": {
"number": "2",
"street": "st1"
}
},
{
"customerId": "3",
"Address": {
"number": "3"
}
}
]
}
In this data the third item customerId: 3
is invalid since it's missing the street
field in address
. Is there any way for me to get out the filtered items in data
that are valid?
I tried errors.instance, but it gives me only up to Address
for example
"Address": {
"number": "3"
}
Ideally what I want out is the following
{
"source": "app",
"data": [
{
"customerId": "1",
"Address": {
"number": "1",
"street": "st1"
}
},
{
"customerId": "2",
"Address": {
"number": "2",
"street": "st1"
}
}
]
}
来源:https://stackoverflow.com/questions/57000651/jsonschema-filter-out-invalid-items