SwiftJSONParser alternatives and similar libraries
Based on the "JSON" category.
Alternatively, view SwiftJSONParser alternatives based on common mentions on social networks and blogs.
-
SwiftyJSON
The better way to deal with JSON data in Swift. -
HandyJSON
A handy swift json-object serialization/deserialization library -
AlamofireObjectMapper
An Alamofire extension which converts JSON response data into swift objects using ObjectMapper -
Gloss
[Deprecated] A shiny JSON parsing library in Swift :sparkles: Loved by many from 2015-2021 -
EVReflection
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift -
Decodable
[Probably deprecated] Swift 2/3 JSON unmarshalling done (more) right -
JSONHelper
โ Convert anything into anything in one operation; JSON data into class instances, hex strings into UIColor/NSColor, y/n strings to booleans, arrays and dictionaries of these; anything you can make sense of! -
Himotoki
A type-safe JSON decoding library purely written in Swift -
Genome
A simple, type safe, failure driven mapping library for serializing JSON to models in Swift 3.0 (Supports Linux) -
CodableAlamofire
An extension for Alamofire that converts JSON data into Decodable objects. -
Elevate
Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable. -
JSONCodable
Hassle-free JSON encoding and decoding in Swift -
JSONNeverDie
Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die -
ModelRocket
An iOS framework for creating JSON-based models. Written in Swift. -
Tailor
:necktie:A super fast & convenient object mapper tailored for your needs -
AlamofireJsonToObjects
An Alamofire extension which converts JSON response data into swift objects using EVReflection -
Alembic
:alembic: Functional JSON Parser - Linux Ready :penguin: -
Brick
:droplet: A generic view model for both basic and complex scenarios -
PPJSONSerialization
The Ultimate JSON Serialization for Swift. -
JSONParserSwift
Framework for easily parsing your JSON data directly to Swift object. -
JsonSwiftson
A JSON parser with concise API written in Swift. -
SafeDecoder
A Codable extension to decode arrays and to catch & log all decoding failures
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of SwiftJSONParser or a related project?
README
Parse JSON like a badass
Full disclaimer regarding performance
For production apps (or if you care about efficiency at all), I highly recommend using SwiftyJSON over this library. After benchmarking, I found that SwiftJSONParser could be up to 7x slower than SwiftyJSON.
This sucks
let jsonData = NSData(contentsOfURL: NSURL(string: url))
var jsonErrorOptional: NSError?
let jsonOptional: AnyObject! = NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions(0), error: &jsonErrorOptional)
if let json = jsonOptional as? Dictionary<String, AnyObject> {
if let other = json["other"] as? Dictionary<String, AnyObject> {
if let nicknames = other["nicknames"] as? Array<String> {
if let handle = nicknames[0] as AnyObject? as? String {
println("Some folks call me \(handle)")
}
}
}
}
This is readable
let jsonData = NSData(contentsOfURL: NSURL(string: url))
let parser = JSONParser(jsonData)
if let handle = parser.getString("other.nicknames[0]") {
println("Some folks call me \(handle)")
}
Usage
Sample JSON payload we want to parse
{
"name": "Mike",
"favorite_number": 19,
"gpa": 2.6,
"favorite_things": ["Github", 42, 98.6],
"other": {
"city": "San Francisco",
"commit_count": 9000,
"nicknames": ["mrap", "Mikee"]
}
}
Get values of a specific type. Returns optionals
if let name = parser.getString("name") {
println("My name is \(name)")
}
if let number = parser.getInt("favorite_number") {
println("\(number) is my favorite number!")
}
if let gpa = parser.getDouble("gpa") {
println("My stellar highschool gpa was \(gpa)")
}
Or get AnyObject
if you're not sure
if let city = parser.get("other.city") {
// city will be type AnyObject
}
Get an Array of values
if let favorites = parser.getArray("favorite_things") {
// favorites => ["Github", 42, 98.6]
}
Error Handling
If you're not sure about incoming json data, check it first
let badJsonData = NSData(contentsOfURL: NSURL(string: url))
let parser = JSONParser(badJsonData)
// Check for an error
if parser.error != nil {
// Do stuff with json
} else {
// Handle the error
println(parser.error)
}
Installation
The best way to use SwiftJSONParser is to import it as a framework.
- Clone a local copy of SwiftJSONParser in any directory you'd like.
git clone [email protected]:mrap/SwiftJSONParser.git
Drag
SwiftJSONParser.xcodeproj
into your project's project navigatorAdd SwiftJSONParser as a Target Dependency.
Go to your App Target > Build Phases
In Target Dependencies, press
+
, selectSwiftJSONParser