Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wheely/bunnyhop

Simple and clean JSON for Swift
https://github.com/wheely/bunnyhop

json

Last synced: about 1 month ago
JSON representation

Simple and clean JSON for Swift

Awesome Lists containing this project

README

        

# Bunnyhop
JSON library for Swift that extensively uses type inference and no extra syntax.

## Hello World

```swift
struct Bunny {
let name: String?
let age: Int
}

extension Bunny: JSONDecodable, JSONEncodable {
init?(JSONValue: JSON) {
if let age: Int = JSONValue["age"]?.decode() {
self.init(name: JSONValue["name"]?.decode(), age: age)
} else {
return nil
}
}

var JSONValue: JSON {
return ["name": name, "age": age]
}
}

// Encoding
let spikeJSON: JSON = ["name": "Spike", "age": 1]
let spike: Bunny? = spikeJSON.decode() // {name "Spike", age 1}

// Decoding
spikeJSON == JSON(spike!) // true
```