Swiftpack.co - makoni/parsable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by makoni.
makoni/parsable 1.0.4
Syntax sugar that makes JSON decoding more elegant.
⭐️ 1
🕓 6 weeks ago
.package(url: "https://github.com/makoni/parsable.git", from: "1.0.4")


Syntax sugar that makes JSON decoding more elegant.

Build and test


Swift Package Manager

Add to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/makoni/parsable.git", from: "1.0.0"),


An example struct or class should conform to Codable and Parseable protocols:

#import Parsable

// Example struct that conforms to Codable protocol
struct SampleErrorModel: Codable {
    var error: String?
    var code: Int?

// Parseable protocol conformance. That's it.
extension SampleErrorModel: Parseable {
    typealias ParseableType = Self

let sampleModel = SampleErrorModel(error: "error message text", code: 404)

Struct -> JSON data:

let jsonData = SampleErrorModel.encode(
    fromEncodable: error, 
    withDateEncodingStrategy: .millisecondsSince1970

JSON data -> struct:

let decodedModel = SampleErrorModel.decodeFromData(
    data: jsonData,
    withDateDecodingStrategy: .millisecondsSince1970

Date decoding strategy is optional. Default value is:

let jsonData = SampleErrorModel.encode(fromEncodable: sampleModel)
let decodedModel = SampleErrorModel.decodeFromData(data: jsonData)

Here's some documentation.


Stars: 1
Last commit: 6 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

6 weeks ago

Small refactoring. Added documentation.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics