Latest 1.0.0
Homepage https://github.com/devxoul/RxJSON
License MIT
Platforms ios 8.0, osx 10.11, tvos 9.0, watchos 2.0
Dependencies RxSwift
Authors

Swift
CocoaPods
Build Status
codecov

RxSwift wrapper for JSON.

At a Glance

This is an example of converting a json dictionary observable to a string observable:

URLSession.shared.rx.json(url: "https://api.github.com/repos/ReactorKit/ReactorKit")
  .mapJSON("owner")              // Observable<Any> -> Observable<Any>
  .mapJSON("login", String.self) // Observable<Any> -> Observable<String>
  .bind(to: ownerNameLabel.rx.text)

mapJSON() supports both JSON dictionary and array:

// Dictionary
Observable<Any>.mapJSON("key")           // Observable<Any>
Observable<Any>.mapJSON("key", Int.self) // Observable<Int>

// Array
Observable<Any>.mapJSON(at: 2)              // Observable<Any>
Observable<Any>.mapJSON(at: 3, String.self) // Observable<String>

mapJSON() will throw a RxJSONError when there’s no value for given accessor or fails to cast to a given type:

// Dictionary
source.mapJSON("unknownKey")    // Event.error(RxJSONError.valueNotFound)
source.mapJSON("name", Int.key) // Event.error(RxJSONError.castingFailed)

// Array
source.mapJSON(at: -1)          // Event.error(RxJSONError.valueNotFound)
source.mapJSON(at: 0, Int.key)  // Event.error(RxJSONError.castingFailed)

Installation

Contributing

Any discussions and pull requests are welcomed 💖

To create a Xcode project:

$ swift package generate-xcodeproj

License

RxJSON is under MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "RxJSON",
    "version": "1.0.0",
    "summary": "RxSwift wrapper for JSON",
    "homepage": "https://github.com/devxoul/RxJSON",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Suyeol Jeon": "[email protected]"
    },
    "source": {
        "git": "https://github.com/devxoul/RxJSON.git",
        "tag": "1.0.0"
    },
    "source_files": "Sources/**/*.swift",
    "dependencies": {
        "RxSwift": [
            ">= 4.0.0-beta.0"
        ]
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.11",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This