I have a payload where I need to check for a few specific validation and if validation doesnt succeed I want to add an error to a new array in the payload.
Input :
[
{
"order": "123",
"product": "",
"invoice": "Lock"
},
{
"order": "123",
"product": "456",
"invoice": ""
}
]
In above input I need to check if Invoice == 'Locked' and Product != null, order needs to be checked against a different json array to see if that value exist but I just want to get an idea on invoice and product o how to get different validation and add errors to error array..
Expected output should be :
[
{
"order": "123",
"product": "",
"invoice": "Lock",
"Errors" : {
"Error" : true,
"Error Message" : "Invoice is not "Locked", product is null"
}
},
{
"order": "123",
"product": "456",
"invoice": "123",
"Errors" : {
"Error" : false,
"Error Message" : ""
}
}
]
I want to be able to check for different validations for different keys.
I am able to achieve below output, where I am using a different function for each individual key and adding error for each keys but it is becoming very challenging to filter out which error has occurred?
[
{
"order": "123",
"product": "",
"invoice": "",
"Errors": {
"Order ": "Order is NULL,",
"Product": "",
"Invoice": ""
}
},
{
"order": "123",
"product": "456",
"invoice": "123",
"Errors": {
"Order ": "",
"Product": "",
"Invoice": ""
}
}
]
Even if I can figure out from above output which one of the objects has errors in it, that will server the purpose.
How do I get the desired output shown above with Errors
array with {Error, error message}
?
question from:
https://stackoverflow.com/questions/65878229/how-to-add-error-to-payload-for-several-keys-value-is-null-in-payload-in-datawe