SwiftJSONParser alternatives and similar libraries
Based on the "JSON" category.
Alternatively, view SwiftJSONParser alternatives based on common mentions on social networks and blogs.
-
AlamofireObjectMapper
An Alamofire extension which converts JSON response data into swift objects using ObjectMapper -
Gloss
DISCONTINUED. [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 -
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! -
Genome
A simple, type safe, failure driven mapping library for serializing JSON to models in Swift 3.0 (Supports Linux) -
CodableAlamofire
DISCONTINUED. 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. -
JSONNeverDie
Auto reflection tool from JSON to Model, user friendly JSON encoder / decoder, aims to never die -
AlamofireJsonToObjects
An Alamofire extension which converts JSON response data into swift objects using EVReflection -
DynamicUI
Create a SwiftUI user interface through a JSON file. The JSON file will contain the structure of the user interface, and the program will create the user interface based on the JSON file.
CodeRabbit: AI Code Reviews for Developers
* 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