I'm trying to (at least) decode JSON that looks something like this:
{
"type": "row",
"title": "Hello...",
"subtitle": "...from JSON"
}
However, "type" defines which Codable Type this represents (e.g. "row" to Row
). I've seen many examples where "type" is one value and the rest are nested in a "payload" value like this:
{
"type": "row",
"payload:
{
"title": "Hello...",
"subtitle": "...from JSON"
}
}
But in my scenario, it's flattened. How can I write a custom decoder that can read the type and THEN (re?)decode with that knowledge?