I have a Json-file with multiple "Dozzs" objects.
Inside each "Dozzs" object is one or multiple "Dozz" objects. So I have a mix of "Dozzs" objects with one "Dozz" and "Dozzs" objects with an array of "Dozz" objects.
But I can't say in my struct let doz: [Dozz]
, JSONDecoder doesn't want to parse one single "Dozz" into a "Dozz"-array if that is the case.
Is there a way to parse(if there is only one Dozz object inside Dozzs) that one into an array? So I have always in my struct an Dozz-Array with one or more objects and JSONDecoder doesn't crashes.
Here is my current struct:
struct Dozzs : Codable {
let doz : Dozz?
//let doz: [Dozz]?
}
Here is the json:
{
"test" : [
{
"dozzs":
{
"doz": {
"-type": "Person",
"-key": "125"
}
}
},
{
"dozzs": [
{
"doz": {
"-type": "Person",
"-key": "123"
}
},
{
"doz": {
"-type": "Person",
"-key": "124,"
}
}
]
}
]
}
Help would be great