I'm trying to create a struct to model the following bit of JSON, where the high level properties ("Blue Team" and "Green Team") don't have specified keys.
{
"Teams": [
{
"Blue Team": {
"motto": "We're the best",
"players": [
{
"name": "Bob",
"skill": "jumping really high",
"birthday": 1546326611,
},
{
"name": "Julie",
"skill": "really strong",
"birthday": 1546413133,
},
{
"name": "Kirsten",
"skill": "smarty pants",
"birthday": 1546499716,
}
]
},
"Green Team": {... // same structure as above }
}
]
}
I believe I'm close, but I'm not sure how to represent the Blue Team
and Red Team
. This is what I have so far:
struct AllTeams: Codable {
let Teams: [String : Team]
struct Team: Codable {
//let <property>: ???
}
struct ???: Codable {
let motto: String
let players: [Player]
}
struct Player: Codable {
let name: String
let skill: String
let birthday: Int // will need to convert this
}
}