I would like to represent the following JSON as a struct that conforms to Codable
:
{
"trooper": {"name": "Trooper", "type": "alsatian"},
"spot": {"name": "Spot", "type": "labrador"},
"sniffles": {"name": "Sniffles", "type": "poodle"}
}
The list is not exhaustive i.e. there can be any number of dogs in the list.
The {"name": "Sniffles", "type": "poodle"}
part is easy, and can be done like this:
struct Dog: Codable {
var name: String
var type: String
}
But what about the root level?