I am bulding a Logic Apps workflow and I need to handle 2 different type of responses returned back by a 3rd API service by using an if condition.
The API response in case of the API being able to process the data correctly looks pretty much like this:
[ { "Input": { "Address": "", "Address1": "Sageweg 27", "Address2": "Neuenburg", "Address3": "", "Address4": "", "Address5": "", "Address6": "", "Address7": "", "Address8": "", "Country": "DEU", "SuperAdministrativeArea": "", "AdministrativeArea": "", "SubAdministrativeArea": "", "Locality": "", "DependentLocality": "", "DoubleDependentLocality": "", "Thoroughfare": "", "DependentThoroughfare": "", "Building": "", "Premise": "", "SubBuilding": "", "PostalCode": "79395", "Organization": "", "PostBox": "" }, "Matches": [ { "AQI": "A", "AVC": "V44-I44-P6-100", "Address": "Sägeweg 27,79395 Neuenburg Am Rhein", "Address1": "Sägeweg 27", "Address2": "79395 Neuenburg Am Rhein", "AdministrativeArea": "Baden-Württemberg", "CountryName": "Germany", "DeliveryAddress": "Sägeweg 27", "DeliveryAddress1": "Sägeweg 27", "GeoAccuracy": "P4", "GeoDistance": "0.0", "HyphenClass": "C", "ISO3166-2": "DE", "Country": "DE", "ISO3166-3": "DEU", "ISO3166-N": "276", "Latitude": "47.807820", "Locality": "Neuenburg Am Rhein", "Longitude": "7.569160", "MatchRuleLabel": "Rlfnp", "PostalCode": "79395", "PostalCodePrimary": "79395", "Premise": "27", "PremiseNumber": "27", "SubAdministrativeArea": "Reg.-Bez. Freiburg", "Thoroughfare": "Sägeweg" } ] }, { "Input": { "Address": "", "Address1": "Schubartstr. 111", "Address2": "Bietigheim-Bissingen", "Address3": "74321", "Address4": "", "Address5": "", "Address6": "", "Address7": "", "Address8": "", "Country": "DEU", "SuperAdministrativeArea": "", "AdministrativeArea": "", "SubAdministrativeArea": "", "Locality": "", "DependentLocality": "", "DoubleDependentLocality": "", "Thoroughfare": "", "DependentThoroughfare": "", "Building": "", "Premise": "", "SubBuilding": "", "PostalCode": "", "Organization": "", "PostBox": "" }, "Matches": [ { "AQI": "A", "AVC": "V44-I44-P6-100", "Address": "Schubartstr. 111,74321 Bietigheim-Bissingen", "Address1": "Schubartstr. 111", "Address2": "74321 Bietigheim-Bissingen", "AdministrativeArea": "Baden-Württemberg", "CountryName": "Germany", "DeliveryAddress": "Schubartstr. 111", "DeliveryAddress1": "Schubartstr. 111", "DependentLocality": "Bissingen", "GeoAccuracy": "P4", "GeoDistance": "0.0", "HyphenClass": "C", "ISO3166-2": "DE", "Country": "DE", "ISO3166-3": "DEU", "ISO3166-N": "276", "Latitude": "48.942220", "Locality": "Bietigheim-Bissingen", "Longitude": "9.106600", "MatchRuleLabel": "Rlfnp", "PostalCode": "74321", "PostalCodePrimary": "74321", "Premise": "111", "PremiseNumber": "111", "SubAdministrativeArea": "Reg.-Bez. Stuttgart", "Thoroughfare": "Schubartstr." } ] } ]
while in case of "error" looks like this:
{ "Number": 18, "Description": "Missing or invalid parameters", "Cause": "A required parameter was not supplied of the value of a parameter cannnot be converted into the right type.", "Resolution": "Check the parameters passed and their values against the specification for this service." }
How can I set the schema for the Parse JSON action considering that in the success case it's an array, while in the error case it's an object?
Apologies if I previously asked again this question but the success response I pasted here was wrong, by bad.
Thanks all for the time spent in helping.
You can use the below given schema to parse both the success and failure response.
{
"oneOf": [
{
"type": "object",
"properties": {
"Number": {
"type": "integer"
},
"Description": {
"type": "string"
},
"Cause": {
"type": "string"
},
"Resolution": {
"type": "string"
}
},
"additionalProperties": false
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"Input": {
"type": "object",
"properties": {
"Address": {
"type": "string"
},
"Address1": {
"type": "string"
},
"Address2": {
"type": "string"
},
"Address3": {
"type": "string"
},
"Address4": {
"type": "string"
},
"Address5": {
"type": "string"
},
"Address6": {
"type": "string"
},
"Address7": {
"type": "string"
},
"Address8": {
"type": "string"
},
"Country": {
"type": "string"
},
"SuperAdministrativeArea": {
"type": "string"
},
"AdministrativeArea": {
"type": "string"
},
"SubAdministrativeArea": {
"type": "string"
},
"Locality": {
"type": "string"
},
"DependentLocality": {
"type": "string"
},
"DoubleDependentLocality": {
"type": "string"
},
"Thoroughfare": {
"type": "string"
},
"DependentThoroughfare": {
"type": "string"
},
"Building": {
"type": "string"
},
"Premise": {
"type": "string"
},
"SubBuilding": {
"type": "string"
},
"PostalCode": {
"type": "string"
},
"Organization": {
"type": "string"
},
"PostBox": {
"type": "string"
}
}
},
"Matches": {
"type": "array",
"items": {
"type": "object",
"properties": {
"AQI": {
"type": "string"
},
"AVC": {
"type": "string"
},
"Address": {
"type": "string"
},
"Address1": {
"type": "string"
},
"Address2": {
"type": "string"
},
"AdministrativeArea": {
"type": "string"
},
"CountryName": {
"type": "string"
},
"DeliveryAddress": {
"type": "string"
},
"DeliveryAddress1": {
"type": "string"
},
"DependentLocality": {
"type": "string"
},
"GeoAccuracy": {
"type": "string"
},
"GeoDistance": {
"type": "string"
},
"HyphenClass": {
"type": "string"
},
"ISO3166-2": {
"type": "string"
},
"Country": {
"type": "string"
},
"ISO3166-3": {
"type": "string"
},
"ISO3166-N": {
"type": "string"
},
"Latitude": {
"type": "string"
},
"Locality": {
"type": "string"
},
"Longitude": {
"type": "string"
},
"MatchRuleLabel": {
"type": "string"
},
"PostalCode": {
"type": "string"
},
"PostalCodePrimary": {
"type": "string"
},
"Premise": {
"type": "string"
},
"PremiseNumber": {
"type": "string"
},
"SubAdministrativeArea": {
"type": "string"
},
"Thoroughfare": {
"type": "string"
}
}
}
}
},
"additionalProperties": false
}
}
]
}
Success Payload-
Failure Payload -