I am attempting to decode an array of strings, where in the returned JSON is an array of strings but also contains nested arrays
Like:
{ "people": ["Alice", "Bob"],
"departments": [["Accounts", "Sales"]]
}
My Swift code:
let decoder = JSONDecoder()
let model = try decoder.decode([String:[String]].self, from: dataResponse)
print(model as Any)
I want to be able to decode the departments, but each time I do it complains that:
Error typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [_DictionaryCodingKey(stringValue: "departments", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "Expected to decode String but found an array instead.", underlyingError: nil))
I understand that this is because the decoder is expecting a string with an array of strings
I am wondering if I can also tell it to expect multiple, nested arrays of strings.