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.
Success Payload-
Failure Payload -