struct User : Codable { var id : Int var firstname : String var lastname : String var email : String ? If my object is a Class, we would need to re-implement Encodable and Decodable and their respective methods encode(to encoder: Encoder) and init(from decoder: Decoder) . In conclusion, we’ve seen how to encode and decode JSON data in Swift 4 using Codable protocols and how to customize our object keys represent more complex data structure.