Skip to content

Latest commit

 

History

History
83 lines (55 loc) · 1.61 KB

README.md

File metadata and controls

83 lines (55 loc) · 1.61 KB

swift-JSON

Swift: 3.0.1 platforms: macOS, iOS, tvOS, Linux Carthage: compatible SwiftPM: compatible

JSON

Yet another Swift JSON encoder/decoder. Intended to be RFC7159 compliant.

Getting Started

Swift Package Manager

import PackageDescription

let package = Package(
    name: "hello",
    dependencies: [
        .Package(url: "https://github.com/rintaro/Swift-JSON.git", majorVersion: 0, minor: 2),
    ]
)

Carthage

github "rintaro/swift-JSON" ~> 0.2

Using JSON

decode

(a.k.a. parse or deserialize)

import JSON

let jsonData: Data = ...

do {

    let value = try JSON.decode(jsonData)
    // do something...

} catch let e as JSONParsingError {
    print(e)
}

encode

(a.k.a. dump or serialize)

import JSON

let value: Any = ...

do {

    let data = try JSON.encode(value)
    // do something...

} catch let e as JSONPrintingError {
    print(e)
}

Requirements

  • Swift 3.0.1 (Xcode8.1 on macOS)
  • Foundation