Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/devxoul/RxJSON

RxSwift wrapper for JSON
https://github.com/devxoul/RxJSON

json rxswift

Last synced: 3 months ago
JSON representation

RxSwift wrapper for JSON

Awesome Lists containing this project

README

        

# RxJSON

![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg)
[![CocoaPods](http://img.shields.io/cocoapods/v/RxJSON.svg)](https://cocoapods.org/pods/RxJSON)
[![Build Status](https://travis-ci.org/devxoul/RxJSON.svg?branch=master)](https://travis-ci.org/devxoul/RxJSON)
[![codecov](https://img.shields.io/codecov/c/github/devxoul/RxJSON.svg)](https://codecov.io/gh/devxoul/RxJSON)

RxSwift wrapper for JSON.

## At a Glance

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

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

`mapJSON()` supports both JSON dictionary and array:

```swift
// Dictionary
Observable.mapJSON("key") // Observable
Observable.mapJSON("key", Int.self) // Observable

// Array
Observable.mapJSON(at: 2) // Observable
Observable.mapJSON(at: 3, String.self) // Observable
```

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

```swift
// 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

* **Using [CocoaPods](https://cocoapods.org)**:

```ruby
pod 'RxJSON'
```

* **Using [Carthage](https://github.com/Carthage/Carthage)**:

This is not supported yet. See [Carthage#1945](https://github.com/Carthage/Carthage/pull/1945) for details.

## Contributing

Any discussions and pull requests are welcomed 💖

To create a Xcode project:

```console
$ swift package generate-xcodeproj
```

## License

RxJSON is under MIT license. See the [LICENSE](LICENSE) file for more info.