JSONHelper alternatives and similar libraries
Based on the "JSON" category.
Alternatively, view JSONHelper 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 -
CodableAlamofire
DISCONTINUED. An extension for Alamofire that converts JSON data into Decodable objects. -
Genome
A simple, type safe, failure driven mapping library for serializing JSON to models in Swift 3.0 (Supports Linux) -
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.
SaaSHub - Software Alternatives and Reviews
* 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 JSONHelper or a related project?
README
JSONHelper
Convert anything into anything in one operation; hex strings into UIColor/NSColor, JSON strings into class instances, y/n strings to booleans, arrays and dictionaries of these; anything you can make sense of!
Latest version requires iOS 8+ and Xcode 7.3+
Table of Contents
- Installation
- The <-- Operator
- Convertible Protocol
- Deserializable Protocol (with JSON deserialization example)
- Serializable Protocol
Installation
CocoaPods
Add the following line in your Podfile
.
pod "JSONHelper"
Carthage
Add the following line to your Cartfile.
github "isair/JSONHelper"
Then do carthage update
. After that, add the framework to your project.
The <-- Operator
The <--
operator takes the value on its right hand side and tries to convert it into the type of the value on its left hand side. If the conversion fails, an error is logged on debug builds. If it's successful, the value of the left hand side variable is overwritten. It's chainable as well.
If the right hand side value is nil or the conversion fails, and the left hand side variable is an optional, then nil is assigned to it. When the left hand side is non-optional, the current value of the left hand side variable is left untouched.
Using this specification let's assume you have a dictionary response that you retrieved from some API with hex color strings in it, under the key colors
, that you want to convert into an array of UIColor instances. Also, to fully use everything we know, let's also assume that we want to have a default value for our color array in case the value for the key we're looking for does not exist (is nil).
var colors = [UIColor.blackColor(), UIColor.whiteColor()]
// Assume we have response { "colors": ["#aaa", "#b06200aa"] }
colors <-- response[colorsKey]
Convertible Protocol
If your type is a simple value-like type, adopting the Convertible protocol is the way to make your type work with the <--
operator.
Example:
struct Vector2D: Convertible {
var x: Double = 0
var y: Double = 0
init(x: Double, y: Double) {
self.x = x
self.y = y
}
static func convertFromValue<T>(value: T?) throws -> Self? {
guard let value = value else { return nil }
if let doubleTupleValue = value as? (Double, Double) {
return self.init(x: doubleTupleValue.0, y: doubleTupleValue.1)
}
throw ConversionError.UnsupportedType
}
}
var myVector: Vector2D?
myVector <-- (1.0, 2.7)
Deserializable Protocol
While you can basically adopt the Convertible
protocol for any type, if your type is always converted from a dictionary or a JSON string then things can get a lot easier with the Deserializable
protocol.
Example:
class User: Deserializable {
static let idKey = "id"
static let emailKey = "email"
static let nameKey = "name"
static let avatarURLKey = "avatar_url"
private(set) var id: String?
private(set) var email: String?
private(set) var name = "Guest"
private(set) var avatarURL = NSURL(string: "https://mysite.com/assets/default-avatar.png")
required init(dictionary: [String : AnyObject]) {
id <-- dictionary[User.idKey]
email <-- dictionary[User.emailKey]
name <-- dictionary[User.nameKey]
avatarURL <-- dictionary[User.avatarURLKey]
}
}
var myUser: User?
user <-- apiResponse["user"]
Serializable Protocol
// Serialization is coming soon. I'll probably not add a new protocol and just rename and update the Deserializable protocol and turn it into a mixin.
*Note that all licence references and agreements mentioned in the JSONHelper README section above
are relevant to that project's source code only.