Latest 2.0.0
License MIT
Platforms ios 10.0
Authors ,


Build Status
CocoaPods Compatible
Coverage Status

MetovaJSONCodable is a lightweight Codable protocol with addtional support for JSON


  • Swift 4.2
  • iOS 9+


MetovaJSONCodable is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MetovaJSONCodable'


Any object that previously conformed to the Codable protocol can now use the JSONCodable protocol.

Object example

struct Token: JSONCodable {

   var tokenID: Int
   var email: String
   var authenticationToken: String


let tokenJSON: JSON = [
    "testID": 1,
    "email": "[email protected]",
    "authenticationToken": "token"

let token = Token(from: tokenJSON)

Custom Date Handling

This pod comes with several child protocols for handling json with custom date formats

Time interval since reference date

struct Token: JSONEpochDateCodable {
    var tokenID: Int
    var email: String
    var authenticationToken: String
    var expirationDate: Date

let tokenJSON: JSON = [
    "tokenID": 1,
    "email": "[email protected]",
    "authenticationToken": "token",
    "expirationDate": 1523560533

let token = Token(from: tokenJSON)

// token.expirationDate is a Date equaling 2018-04-12 19:15:33 +0000

Custom Date foramatter object

We also have a child protocol for supporting a custom date formatter. Here you will need to implement a dateFormatter computed variable that returns a date formatter in order to conform to the protocol

struct Token: JSONCustomDateFormatterCodable {
    var testID: Int
    var email: String
    var expirationDate: Date

    static var dateFormatter: DateFormatter {

        let dateFormatter = DateFormatter()
        dateFormatter.calendar = Calendar(identifier: .iso8601)
        dateFormatter.locale = Locale(identifier: "en_US_POSIX")
        dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)
        dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
        return dateFormatter

let validTestJSONISO8601: JSON = [
    "testID": 2,
    "email": "[email protected]",
    "expirationDate": "2016-12-31T17:56:27.000Z"

let token = Token(from: tokenJSON)

// token.expirationDate is a Date equaling 2016-12-31 17:56:27 +0000

Custom Child Protocols

If you want to define your own date formatting strategy or some other permutation to the default coder/decoder, you simply need to make a child protocol and implement your own ecoder/coder

public protocol JSONDecodeableIOS8601: JSONDecodable {}

public extension JSONDecodeableIOS8601 {

    static var jsonDecoder: JSONDecoder {

        let decoder = JSONDecoder()
        decoder.dateDecodingStrategy = .iso8601
        return decoder


Documentation can be found here.


MetovaJSONCodable is owned and maintained by Metova Inc.



MetovaJSONCodable is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "MetovaJSONCodable",
    "version": "2.0.0",
    "summary": "MetovaJSONCodable is a small utility class that extends codable for easier JSON support",
    "description": "MetovaJSONCodable is a simple protocol implemented on top of the existing codable protocol with specialized support for JSON",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "Kalan Stowe": "[email protected]",
        "Nick Griffith": "[email protected]"
    "platforms": {
        "ios": "10.0"
    "swift_version": "4.2",
    "source": {
        "git": "",
        "tag": "2.0.0"
    "source_files": "MetovaJSONCodable/*.swift"

Pin It on Pinterest

Share This