Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/devxoul/RxJSON
- Owner: devxoul
- License: mit
- Created: 2017-05-27T20:47:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-14T11:47:37.000Z (over 5 years ago)
- Last Synced: 2024-07-18T17:41:21.320Z (4 months ago)
- Topics: json, rxswift
- Language: Swift
- Size: 19.5 KB
- Stars: 33
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.