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

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.

Awesome Lists containing this project

README

        

# A JSON parser with concise API written in Swift

[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![CocoaPods Version](https://img.shields.io/cocoapods/v/JsonSwiftson.svg?style=flat)](http://cocoadocs.org/docsets/JsonSwiftson)
[![License](https://img.shields.io/cocoapods/l/JsonSwiftson.svg?style=flat)](http://cocoadocs.org/docsets/JsonSwiftson)
[![Platform](https://img.shields.io/cocoapods/p/JsonSwiftson.svg?style=flat)](http://cocoadocs.org/docsets/JsonSwiftson)

JsonSwiftson JSON parser for Swift

* 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 PackageDescription

let 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).