What is the most elegant way to create JSON from this structure with the only one parameter
struct SessionStorage: Encodable {
var value: String
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
/// the magic
}
enum CodingKeys: String, CodingKey {
case params
}
}
into this JSON-string?
{"params": {"value": "{value}"}}
I don't want to create nested structs.
Two ways:
Encode the dictionary as
[String: SessionStorage]
Use an envelope struct
IMHO it's not a question of elegance, it's a question of efficiency. The elegance lies in not to specify
encode(to
andCodingKeys