Hopefully someone can help me with my issue.
I'm working with a 3rd party API that, depending on the configuration of the product in the backend, will return a different structure of JSON as the response.
I've included JSON samples showing the different outcomes depending on the product. There are 3 scenarios for the FreeGifts section of the product:
- Has 2 or more free gifts.
- Has 1 free gifts.
- Has no free gifts
Scenario 1
{
"FreeGifts": [{
"FreeGift": [{
"SKU": "BOWS-SMALL-ALFIE"
},
{
"SKU": "BOWS-LARGE-ALONZO"
},
{
"SKU": "BOWS-LARGE-CLANCY"
},
{
"SKU": "BOWS-SMALL-ALVIN"
},
{
"SKU": "BOWS-SMALL-CLARK"
}
]
}]
}
Scenario 2
{
"FreeGifts": [{
"FreeGift": {
"SKU": "BOWS-SMALL-ALVIN"
}
}]
}
Scenario 3
{
"FreeGifts": [
""
]
}
Sites like http://json2csharp.com/ and https://jsonutils.com/ provide me with 3 different class definitions depending on the scenario.
If I had only 1 of these in the structure I could probably deal with it but I have around 7 or 8. It's impossible for me to cater for it.
I'm completely stumped as to how I get Newtonsoft.json to work with the ambiguity that the API produces.
Do I need to go back to the provider and ask them if they can change it?!?