https://github.com/jkolb/jasoom
An easy to use, type safe, Swift wrapper for NSJSONSerialization
https://github.com/jkolb/jasoom
Last synced: about 2 months ago
JSON representation
An easy to use, type safe, Swift wrapper for NSJSONSerialization
- Host: GitHub
- URL: https://github.com/jkolb/jasoom
- Owner: jkolb
- License: mit
- Created: 2015-12-15T17:54:23.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-17T14:43:13.000Z (over 9 years ago)
- Last Synced: 2025-03-13T20:17:58.643Z (3 months ago)
- Language: Swift
- Size: 8.79 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jasoom 1.0.0
#### An easy to use, type safe, Swift wrapper for NSJSONSerialization
[](https://github.com/Carthage/Carthage)
## Parsing JSON
do {
let json = try JSON.parseData(data)
if json["name"].isUndefined {
throw .MissingName
}
if json["info"]["age"].isUndefined {
throw .MissingAge
}
let model = MyModel(
name: json["name"].stringValue!
age: json["info"]["age"].intValue!
married: json["status"]["married"].boolValue ?? false
firstCar: json["cars"][0].stringValue ?? ""
)
}
catch {
// Handle error
}## Generating JSON
var object = JSON.object()
object["name"] = .String("Bob Smith")
object["info"] = JSON.object()
object["info"]["age"] = .Number(10)
object["status"] = JSON.object()
object["status"]["married"] = .Number(true)
object["cars"] = JSON.array()
object["cars"].append(.String("Ford Mustang"))
do {
let data = try object.generateData()
}
catch {
// Handle error
}## Contact
[Justin Kolb](mailto:[email protected])
[@nabobnick](https://twitter.com/nabobnick)## License
Jasoom is available under the MIT license. See the LICENSE file for more info.