So my API service provider has inconsistent JSON response body elements. Specifically, a property that can contain one or many records isn't always passed back as an array. If there are multiple records it is. But if there is only one record then the record is passed back as a singleton.
What I am looking to do in my C# app is to programmatically append the [ ] around the singleton record, so that it's correctly defined as an array with a single element. More of a regex experiment, since I am handling the JSON response body as a string. I know it's perhaps less efficient, but the JSON string is what a third-party "black box" is looking for.
Example of the singleton JSON response body.
{
"Transfer":{
"transferID":"3581",
"sent":"true",
"received":"true"
}
}
And now an example of the array JSON body.
{
"Transfer":[
{
"transferID":"3581",
"sent":"true",
"received":"true"
},
{
"transferID":"3582",
"sent":"true",
"received":"true"
}
]
}
Just looking for the quickest and cleanest way to add the [ and the ] around the singleton Transfer record. Would like a reusable method, since the API service provider passes back other record types this way as well.