Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/wheely/bunnyhop
- Owner: wheely
- License: mit
- Created: 2015-08-18T09:34:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-07T12:23:27.000Z (about 7 years ago)
- Last Synced: 2024-03-25T23:17:14.915Z (9 months ago)
- Topics: json
- Language: Swift
- Size: 139 KB
- Stars: 2
- Watchers: 18
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```