I'm facing problems when I try to deserialize a JSON that is not coming always in the same exact format. The JSON I'm getting is something like this (trimmed for clarity):
{  
  "header": {  
    "code": "4",  
    "description": "Input Validation Error",  
    "errors": {  
      "code": "100",  
      "description": "externalServiceCode: must match '[A-Za-z0-9_]+'"  
    }  
  },  
  "externalCode": "259716_TRAVELAC"  
},  
{  
  "header": {  
    "code": "4",  
    "description": "Input Validation Error",  
    "errors": [  
      {  
        "code": "100",  
        "description": "Currency not valid"  
      },  
      {  
        "code": "100",  
        "description": "Can not be empty"  
      }  
    ]  
  },  
  "externalCode": "259716_TRA"  
}  
As you can see, the "errors" value could be simple:
 "errors":{"code":"1","description":"description"}  
or may come as an array:
 "errors":[{....},{....}].  
I don't have any control on the JSON format (the service where I'm getting it is made by another company).
The thing is that I couldn't find a simple way to parse this JSON into C#. I made the custom classes, and if I try it as a simple object, I miss the data if there are multiple errors, and if I consider it as an array, I don't get anything if the JSON comes with only one error (please note the missing enclosing brackets [ ] in the errors part when there is only one).
Is there any way to solve this? I've tried several approaches, but nothing seems to work.
 
     
     
    