I have this model in Swift:
struct EventModel: Codable {
var eventType: String
var eventName: String?
var attributes: [String: String]?
}
Is it possible to move the attributes to the top level when I convert it to JSON? Example:
var model = EventModel(eventType: "type",
eventName: "name",
attributes: ["attribute1": "One", "attribute2": "Two"])
becomes
{
"eventType" : "type",
"eventName" : "name",
"attribute1" : "One",
"attribute2" : "Two"
}
First, encode the static keys, then encode the attributes into the same encoder: