Say the JSON looks like this:
[
{
"data": {
"children": [
{
"name": "Ralph"
},
{
"name": "Woofer"
}
]
}
},
{
"data": {
"children": [
{
"name": "Spot"
},
{
"name": "Trevor"
}
]
}
}
]
Where you have this very weird structure where there the root item is an array, with two objects, and each of those two objects is an array of Dog
dictionaries.
But the problem is that the Dog
array is two keys in! You have to go through data
and children
to get to it. I saw this answer that depicts doing it with a single key deep, but I can't seem to reproduce the result when it's nested two deep.
I want the result to be (as weird as it seems) something like this, where both lists are maintained separately:
struct Result: Codable {
let dogs1: [Dog]
let dogs2: [Dog]
}
I know I need a custom initializer/decoder, but I'm very unsure of how to access it.