Sometimes my JSON response is like this
{
"products": [
{
"pId": "3564225",
"name": "Maxi Skirt",
"slug": "maxi-skirt",
"sku": "s-navy",
"priority": 10,
"images": [
]
},
{
"pId": "299328304",
"name": "Necklace Setjewellery",
"slug": "american-diamond-necklace-setjewellery",
"sku": "free-size-purple",
"priority": 10,
"images": [
]
}],
"total": 2
}
And Sometimes it looks like this
{
"products": [
],
"total": 0
}
Swift decoder throws following error when parsing empty array response
"*Swift.DecodingError.Context(codingPath: [], debugDescription:
"The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840
"JSON text did not start with array or object and option to allow fragments not set."
UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}*"
How do I write a swift codable struct to handle multiple response JSON like these above?
PS: I can't change anything from server side.