https://github.com/evgenyneu/jsonswiftson
A JSON parser with concise API written in Swift.
https://github.com/evgenyneu/jsonswiftson
json json-parser swift
Last synced: 5 months ago
JSON representation
A JSON parser with concise API written in Swift.
- Host: GitHub
- URL: https://github.com/evgenyneu/jsonswiftson
- Owner: evgenyneu
- License: mit
- Created: 2015-05-10T02:49:09.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-07T23:35:52.000Z (about 8 years ago)
- Last Synced: 2024-10-11T19:19:23.972Z (6 months ago)
- Topics: json, json-parser, swift
- Language: Swift
- Homepage:
- Size: 509 KB
- Stars: 14
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# A JSON parser with concise API written in Swift
[](https://github.com/Carthage/Carthage)
[](http://cocoadocs.org/docsets/JsonSwiftson)
[](http://cocoadocs.org/docsets/JsonSwiftson)
[](http://cocoadocs.org/docsets/JsonSwiftson)
* Maps JSON attributes to different Swift types with just two methods: `map` and `mapArrayOfObjects`.
* The library can be used on any platform that runs Swift.
* Supports casting to optional types.
* Indicates if the mapping was successful.
* Can be used in Swift apps for Apple devices and in open source Swift programs on other platforms.### Example
The following is an example of mapping a JSON text into a Swift `Person` structure.
```Swift
struct Person {
let name: String
let age: Int
}let mapper = JsonSwiftson(json: "{ \"name\": \"Peter\", \"age\": 41 }")
let person = Person(
name: mapper["name"].map() ?? "",
age: mapper["age"].map() ?? 0
)if !mapper.ok { /* report error */ }
```## Setup (Swift 3.0)
There are four ways you can add JsonSwiftson into your project.
#### Add the source file (iOS 7+)
Simply add [JsonSwiftson.swift](https://github.com/evgenyneu/JsonSwiftson/blob/master/JsonSwiftson/JsonSwiftson.swift) file to your Xcode project.
#### Setup with Carthage (iOS 8+)
Alternatively, add `github "evgenyneu/JsonSwiftson" ~> 4.0` to your Cartfile and run `carthage update`.
#### Setup with CocoaPods (iOS 8+)
If you are using CocoaPods add this text to your Podfile and run `pod install`.
use_frameworks!
target 'Your target name'
pod 'JsonSwiftson', git: 'https://github.com/evgenyneu/JsonSwiftson.git', tag: '4.0.0'#### Setup with Swift Package Manager
Add the following text to your Package.swift file and run `swift build`.
```Swift
import PackageDescriptionlet package = Package(
name: "YourPackageName",
targets: [],
dependencies: [
.Package(url: "https://github.com/evgenyneu/JsonSwiftson.git",
versions: Version(3,0,0)..## Alternative solutions
Here is a list of excellent libraries that can help taming JSON in Swift.
* [Argo](https://github.com/thoughtbot/Argo)
* [json-swift](https://github.com/owensd/json-swift)
* [JSONJoy-Swift](https://github.com/daltoniam/JSONJoy-Swift)
* [ObjectMapper](https://github.com/Hearst-DD/ObjectMapper)
* [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON)## License
JsonSwiftson is released under the [MIT License](LICENSE).