Determine which JSON was received.
Posted: Fri Oct 27, 2023 5:39 pm
I am working with a Client to implement the new UPS API's that are changing from XML to JSON. Currently I'm testing the Address Validation API. I am receiving the JSON File to the IFS and using YAJL in Free Form RPGLE to parse. From the Address Validation Request, I can receiving 2 different Address Validation Response Files. I need to determine programmatically which JSON File was received so I can execute the correct parsing routine. I used YAJLGEN to create 2 different Data Structures and YAJLINTO for parsing. I know File #2 has an array of Addresses, but I haven't found a way to recognize the existence or non existence of the array in the received files. What would be the best way to determine which file was received?
File #1:
{
"XAVResponse": {
"Response": {
"ResponseStatus": {
"Code": "1",
"Description": "Success"
}
},
"ValidAddressIndicator": "",
"AddressClassification": {
"Code": "2",
"Description": "Residential"
},
"Candidate": {
"AddressClassification": {
"Code": "2",
"Description": "Residential"
},
"AddressKeyFormat": {
"AddressLine": "54 CLAUDETTE CT",
"PoliticalDivision2": "BUFFALO",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14225",
"PostcodeExtendedLow": "3802",
"Region": "BUFFALO NY 14225-3802",
"CountryCode": "US"
}
}
}
}
File #2:
{
"XAVResponse": {
"Response": {
"ResponseStatus": {
"Code": "1",
"Description": "Success"
}
},
"AmbiguousAddressIndicator": "",
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"Candidate": [
{
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"AddressKeyFormat": {
"AddressLine": "5 EAST AVE N",
"PoliticalDivision2": "FALCONER",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14733",
"PostcodeExtendedLow": "1301",
"Region": "FALCONER NY 14733-1301",
"CountryCode": "US"
}
},
{
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"AddressKeyFormat": {
"AddressLine": "5 EAST AVE S",
"PoliticalDivision2": "FALCONER",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14733",
"PostcodeExtendedLow": "1303",
"Region": "FALCONER NY 14733-1303",
"CountryCode": "US"
}
},
{
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"AddressKeyFormat": {
"AddressLine": "5 EAST AVE S",
"PoliticalDivision2": "FALCONER",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14733",
"PostcodeExtendedLow": "1304",
"Region": "FALCONER NY 14733-1304",
"CountryCode": "US"
}
},
{
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"AddressKeyFormat": {
"AddressLine": "5 EAST AVE N",
"PoliticalDivision2": "FALCONER",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14733",
"PostcodeExtendedLow": "1302",
"Region": "FALCONER NY 14733-1302",
"CountryCode": "US"
}
}
]
}
}
File #1:
{
"XAVResponse": {
"Response": {
"ResponseStatus": {
"Code": "1",
"Description": "Success"
}
},
"ValidAddressIndicator": "",
"AddressClassification": {
"Code": "2",
"Description": "Residential"
},
"Candidate": {
"AddressClassification": {
"Code": "2",
"Description": "Residential"
},
"AddressKeyFormat": {
"AddressLine": "54 CLAUDETTE CT",
"PoliticalDivision2": "BUFFALO",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14225",
"PostcodeExtendedLow": "3802",
"Region": "BUFFALO NY 14225-3802",
"CountryCode": "US"
}
}
}
}
File #2:
{
"XAVResponse": {
"Response": {
"ResponseStatus": {
"Code": "1",
"Description": "Success"
}
},
"AmbiguousAddressIndicator": "",
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"Candidate": [
{
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"AddressKeyFormat": {
"AddressLine": "5 EAST AVE N",
"PoliticalDivision2": "FALCONER",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14733",
"PostcodeExtendedLow": "1301",
"Region": "FALCONER NY 14733-1301",
"CountryCode": "US"
}
},
{
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"AddressKeyFormat": {
"AddressLine": "5 EAST AVE S",
"PoliticalDivision2": "FALCONER",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14733",
"PostcodeExtendedLow": "1303",
"Region": "FALCONER NY 14733-1303",
"CountryCode": "US"
}
},
{
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"AddressKeyFormat": {
"AddressLine": "5 EAST AVE S",
"PoliticalDivision2": "FALCONER",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14733",
"PostcodeExtendedLow": "1304",
"Region": "FALCONER NY 14733-1304",
"CountryCode": "US"
}
},
{
"AddressClassification": {
"Code": "0",
"Description": "Unknown"
},
"AddressKeyFormat": {
"AddressLine": "5 EAST AVE N",
"PoliticalDivision2": "FALCONER",
"PoliticalDivision1": "NY",
"PostcodePrimaryLow": "14733",
"PostcodeExtendedLow": "1302",
"Region": "FALCONER NY 14733-1302",
"CountryCode": "US"
}
}
]
}
}