Popularity
0.3
Stable
Activity
0.0
Stable
2
1
1

Programming language: Swift
License: MIT License
Tags: JSON     Parsing    
Latest version: v1.0.1

NativeJSONMapper alternatives and similar libraries

Based on the "JSON" category.
Alternatively, view NativeJSONMapper alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of NativeJSONMapper or a related project?

Add another 'JSON' Library

README

NativeJSONMapper

Swift 4

Simple Swift 4 encoding & decoding for Codable protocol objects.

Installation

CocoaPods:

pod 'NativeJSONMapper'

Usage

Decoding:

Simple Coding object:

struct CodableModel: Codable {
    var foo: String
    var bar: Int

    enum CodingKeys: String, CodingKey {
        case foo = "foo_key"
        case bar = "bar_key"
    }      
}

Mapping:


// json string
let jsonString: Any = "{\"foo_key\" : \"FooBar\", \"bar_key\" : 1}"

// json dictionary
let jsonDictionary: [String : Any] = ["foo_key" : "FooBar", 
                                      "bar_key" : 1]

// json dictionaries array
let jsonDictionariesArray: [[String : Any]] = (0...10).map { ["foo_key" : "FooBar - \($0)", 
                                                              "bar_key" : $0] }

//Mapping

let mapper = NativeJSONMapper()

do {
    // string
    let fromString = try mapper.map(jsonString, to: CodableModel.self)

    // dictionary
    let fromDictionary = try mapper.map(jsonDictionary, to: CodableModel.self)

    // dictionaries array
    let fromDictionariesArray = try mapper.map(jsonDictionariesArray, to: [CodableModel].self)
} catch {
    // handle error
}

Encoding:

let model = CodableModel(foo: "FooBar", bar: 1)

let mapper = NativeJSONMapper()

do {
    let data = try mapper.encode(model)
    let string = try mapper.encodeToString(model)
    let dictionary = try mapper.encodeToDictionary(model)
} catch {
    // handle error
}

Custom decoder:

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970

let mapper = NativeJSONMapper(decoder: decoder)
//...

License

NativeJSONMapper is under MIT license. See the [LICENSE](LICENSE) file for more info.


*Note that all licence references and agreements mentioned in the NativeJSONMapper README section above are relevant to that project's source code only.