Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/freesuraj/bulldog
Simple yet powerful json parser for iOS and Mac
https://github.com/freesuraj/bulldog
json json-parser swift swiftyjson
Last synced: about 1 month ago
JSON representation
Simple yet powerful json parser for iOS and Mac
- Host: GitHub
- URL: https://github.com/freesuraj/bulldog
- Owner: freesuraj
- License: mit
- Created: 2016-11-19T01:26:37.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-03T06:20:20.000Z (over 5 years ago)
- Last Synced: 2024-08-16T04:02:54.318Z (3 months ago)
- Topics: json, json-parser, swift, swiftyjson
- Language: Swift
- Size: 182 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
![Bulldog: Json Parser](https://raw.githubusercontent.com/freesuraj/Bulldog/master/Assets/logo.png)
[![Build Status](https://travis-ci.org/freesuraj/Bulldog.svg?branch=master)](https://travis-ci.org/freesuraj/Bulldog)
[![Coverage Status](https://coveralls.io/repos/github/freesuraj/Bulldog/badge.svg?branch=master)](https://coveralls.io/github/freesuraj/Bulldog?branch=master)
[![codecov](https://codecov.io/gh/freesuraj/Bulldog/branch/master/graph/badge.svg)](https://codecov.io/gh/freesuraj/Bulldog)
[![Code Climate](https://codeclimate.com/github/freesuraj/Bulldog/badges/gpa.svg)](https://codeclimate.com/github/freesuraj/Bulldog)
[![codebeat badge](https://codebeat.co/badges/b009ba3f-092c-49df-861c-d9f2e758e9e6)](https://codebeat.co/projects/github-com-freesuraj-bulldog)
[![Issue Count](https://codeclimate.com/github/freesuraj/Bulldog/badges/issue_count.svg)](https://codeclimate.com/github/freesuraj/Bulldog)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Bulldog.svg)](http://cocoadocs.org/docsets/Bulldog/)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Platform](https://img.shields.io/cocoapods/p/Bulldog.svg?style=flat)](http://cocoadocs.org/docsets/Bulldog)
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat)](http://twitter.com/iosCook)
[![GitHub forks](https://img.shields.io/github/forks/freesuraj/bulldog.svg?style=social&label=Fork)](https://github.com/freesuraj/bulldog)
[![GitHub stars](https://img.shields.io/github/stars/freesuraj/bulldog.svg?style=social&label=Star)](https://github.com/freesuraj/bulldog)# Bulldog
Bulldog is a super-fast json parser that will keep attacking until it gets the value you desire, or you give up. Just like a bulldog.## Why Bulldog?
- ✅ Super-light
- ✅ Easily extendible
- ✅ Can easily traverse through path of a json object to get the final value while ignoring the type of intermediate objects
- ✅ Utilises the apple's JSONSerialization underneath
- ✅ Well tested with 100% test coverage## Example Usage
Let's suppose we want to parse the following JSON object
### response.json
```
{
"id":123,
"first_name":"Conor",
"last_name":"McGregor",
"age":28,
"height": 171,
"weight":70.5,
"fights":[
{
"id":"UFC 205",
"opponent":"Eddie Alvarez",
"venue":"New York",
"win":true
},
{
"id":"UFC 202",
"opponent":"Nate Diaz",
"venue":"Las Vegas",
"win":true
},
{
"id":"UFC 196",
"opponent":"Nate Diaz",
"venue":"Las Vegas",
"win":false
}
]
}
```### parser.swift
Now to parse the above json file,
```swift
let json: Any = ... // Json from network
let bulldog = Bulldog(json: json)
let name = bulldog.string("first_name") + " " + bulldog.string("last_name") // Conor McGregorlet height = bulldog.int("height") // 171
let weight = bulldog.double("weight") // 70.5// Get first opponent of his fights
let firstOpponent = bulldog.string("fights", 0, "opponent") // Eddie Alvarez
// Get fights array
let fights = bulldog.array("fights") // Returns array of fights// Return the first fight dictionary
let firstFight = bulldog.dictionary("fights", 0) // Returns first fight dictionary// Check if first fight was a win
let isWin = Bulldog(json: fights[0]).boolean("win") // Returns true```
## Installation
### Carthage
Bulldog is available through [Carthage](https://github.com/Carthage/Carthage). To install
it, simply add the following line to your Cartfile:```ruby
git "freesuraj/Bulldog"
```### Cocoapods
Add the following line to your Podfile:
```ruby
pod 'Bulldog'
```
### Manual
Perhaps the easiest way to use is to just copy the file [Bulldog.swift](https://github.com/freesuraj/Bulldog/blob/master/Source/Bulldog.swift) and put it in your project. That's it !!## Example
Please check the [BulldogTests.swift](https://github.com/freesuraj/Bulldog/blob/master/Tests/BulldogTests.swift) file for all possilbe use cases
## About
[![GitHub followers](https://img.shields.io/github/followers/freesuraj.svg?style=social&label=Follow)](https://github.com/freesuraj)
If you found this little tool useful, I'd love to hear about it. You can also follow me on Twitter at [@iosCook](https://twitter.com/ioscook)
## License
Bulldog is available under the MIT license. See the LICENSE file for more info.