Trying to validate the json in azure logic app using json schema validation.
This is my sample json:
{
"address": [
{
"contact": {
"firstName": "myFirstName",
"lastName": "myLastName"
},
"type": "bill"
}
]
}
This is my schema:
{
"if": {
"properties": {
"address": {
"type": "array",
"items": {
"properties": {
"type": {
"const": "bill"
}
}
}
}
}
},
"then": {
"properties": {
"address": {
"type": "array",
"items": {
"properties": {
"contact": {
"type": "object",
"required": [
"firstName"
]
}
}
}
}
}
}
}
If I don’t pass firstName attribute in input json, the validation is getting failed which is expected, but the error message I am getting is not correct. It does not show which attribute is missing. Like in this example I am expecting the message should tell the firstName attribute is missing.
This is output of above validation:
"outputs": {
"errors": [
{
"message": "JSON does not match schema from 'then'.",
"lineNumber": 0,
"linePosition": 0,
"path": "",
"schemaId": "#/then",
"errorType": "then",
"childErrors": []
}
]
}
Any help would be appreciated
2
Answers
I was able to find the workaround and that is using
oneOf
.Modified schema:
Here is the schema validation output for failed scenario.
firstName missing attribute is coming up in error response for conditional schema validation
I have reproduced in my environment and got expected results as below:
Firstly, I have taken a http trigger and then taken parse json step and gave the below schema in it.
Now in response action:
After i have kept runAfter Failed to get the message and then you can use any parallel action also.
Output:
Output In logic app:
Code view:
You can do only this and i do agree with @skin about this.