Latest 0.1.2
Homepage https://github.com/czechboy0/Jay
License MIT
Platforms osx 10.9, ios 8.0, watchos 2.0, tvos 9.0
Authors

Build Status
Latest Release
Platforms
Package Managers

Blog
Twitter Czechboy0

Pure-Swift JSON parser & formatter. Linux & OS X ready. Replacement for NSJSONSerialization.

Jay conforms to the following specifications:

:question: Why?

We all use JSON. Especially when writing server-side Swift that needs to run on Linux. #0dependencies

NSJSONSerialization is not yet fully implemented in the Swift standard libraries, so this is my take on how parsers should work. This is not another JSON mapping utility library. This is an actual JSON parser and formatter. Check out the code, it was fun to write 😇

Features

  • [x] Parsing: data -> JSON object
  • [x] Formatting: JSON object -> data

Usage

Parsing from data

do {
    //get data from disk/network
    let data: [UInt8] = ...

    //ask Jay to parse your data
    let json = try Jay().jsonFromData(data) // Any

    //if it doesn't throw an error, all went well
    if let dictionary = json as? [String: Any] {
        //you have a dictionary root object
    } else if let array = json as? [Any] {
        //you have an array root object
    }
} catch {
    print("Parsing error: (error)")
}

Formatting into data

do {
    //get a json object
    let json: [String: Any] = ... // [String: Any] or [Any]

    //ask Jay to generate data
    let data = try Jay().dataFromJson(json) // [UInt8]

    //send data over network, save to disk
} catch {
    print("Formatting error: (error)")
}

Installation

Swift Package Manager

.Package(url: "https://github.com/czechboy0/Jay.git", majorVersion: 0)

CocoaPods

pod 'Jay'

Swift Versions

This project was originally created for a Swift server running on Linux, so it’s always built (and assumes) the latest Swift and SwiftPM versions. To manage Swift versions easily, I recommend you use swiftenv. You can see which Swift version Jay requires at the moment in the .swift-version file in the root of the repository. Please make sure you’re always running at least that version if you want to use Jay in your project.

gift_heart: Contributing

Please create an issue with a description of your problem or open a pull request with a fix.

v: License

MIT

alien: Author

Honza Dvorsky – http://honzadvorsky.com, @czechboy0

Latest podspec

{
    "name": "Jay",
    "version": "0.1.2",
    "summary": "Pure-Swift JSON parser. Linux & OS X ready",
    "description": "Pure-Swift JSON parser. Linux & OS X ready. Replacement for NSJSONSerialization.",
    "homepage": "https://github.com/czechboy0/Jay",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Honza Dvorsky": "https://honzadvorsky.com"
    },
    "social_media_url": "http://twitter.com/czechboy0",
    "platforms": {
        "osx": "10.9",
        "ios": "8.0",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/czechboy0/Jay.git",
        "tag": "0.1.2"
    },
    "source_files": "Sources/Jay/*.swift"
}

Pin It on Pinterest

Share This