Vapor3 JSON encode & Decode
Clash Royale CLAN TAG #URR8PPP Vapor3 JSON encode & Decode I'm having to use a FoundationDB database for a project. It stores data as a key:value pair stored as Bytes. I want to store a JSON object mapped to a struct I have. I want to be able save the data as an encoded JSON object and then be able to recreate the JSON object by reading the value Bytes from the DB. In my CreateRecord function I pass a JSON in a request and use it to create my Country object. I need to convert the type Data into Bytes to store it. So far I have come up with this. let data: Bytes = try JSONEncoder().encode(country).base64URLEncodedString() Then, when I read the record from the database I need to be able to reverse the process to create my Country object from the Bytes that store the JSON. let mycountry:Country = try decoder.decode(Country.self, from: Data(bytes: DBrecord.value) ) The struct is: struct struct Country: Content { var country_name: String var timezone: String var default...