Migration to Codable

For the cover art migration from gracenote to coverartarchive and discogs, additional json parsing was required. So far this was done using SwiftyJSON, but after reading how easy it should be to use the Codable protocol, I took the leap for the new code. And indeed easy it is.

// Define the relevant data-elements to pull from the json data    
struct Release: Codable {
    var id: String
struct ReleaseGroup: Codable {
    var id: String
struct Response: Codable {
    var releaseGroups: [ReleaseGroup]?
    enum CodingKeys: String, CodingKey {
        case releaseGroups = "release-groups"

// Create a decoder, and pass in the json data.
let jsonDecoder = JSONDecoder()
let response = try jsonDecoder.decode(Response.self, from: json)

Leave a Reply

Your email address will not be published. Required fields are marked *