Pistachio alternatives and similar libraries
Based on the "JSON" category.
Alternatively, view Pistachio alternatives based on common mentions on social networks and blogs.
-
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! -
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. -
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 -
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. -
SafeDecoder
A Codable extension to decode arrays and to catch & log all decoding failures
Appwrite - The open-source backend cloud platform
* 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 Pistachio or a related project?
README
Pistachio
Pistachio is a generic model framework. By leveraging lenses and value transformers, it allows you to create type safe adapters for any recursive data structure, be it JSON, YAML or XML.
If you are already familiar with Argo, take a look at Pistachiargo.
Installation
Carthage
Carthage is a simple, decentralized dependency manager for Cocoa.
- Add Pistachio to your Cartfile:
github "felixjendrusch/Pistachio" ~> 0.2
Run
carthage update
to fetch and build Pistachio and its dependencies.
Usage
Let's start by defining a very simple model:
struct Origin {
var city: String
init(city: String = "") {
self.city = city
}
}
struct Person {
var name: String
var origin: Origin
init(name: String = "", origin: Origin = Origin()) {
self.name = name
self.origin = origin
}
}
A lens is basically just a combination of a getter and a setter, providing a view on your model:
struct OriginLenses {
static let city = Lens(get: { $0.city }, set: { (inout origin: Origin, city) in
origin.city = city
})
}
struct PersonLenses {
static let name = Lens(get: { $0.name }, set: { (inout person: Person, name) in
person.name = name
})
static let origin = Lens(get: { $0.origin }, set: { (inout person: Person, origin) in
person.origin = origin
})
}
It can be used to access and modify your model:
var person = Person(name: "Felix", origin: Origin(city: "Berlin"))
person = set(PersonLenses.name, person, "Robb")
get(PersonLenses.name, person) // == "Robb"
And you can compose, lift, etc. them:
let composed = PersonLenses.origin >>> OriginLenses.city
person = set(composed, person, "New York")
get(composed, person) // == "New York"
With lenses and value transformers, you can create adapters for your models:
struct Adapters {
static let origin = DictionaryAdapter(specification: [
"city_name": map(OriginLenses.city, StringToAnyObjectValueTransformers)
], dictionaryTansformer: DictionaryToAnyObjectValueTransformers, value: Origin())
static let person = DictionaryAdapter(specification: [
"name": map(PersonLenses.name, StringToAnyObjectValueTransformers),
"origin": map(PersonLenses.origin, origin)
], dictionaryTansformer: DictionaryToAnyObjectValueTransformers, value: Person())
}
Use fix
to create adapters for recursive models:
let adapter: DictionaryAdapter<Key, Value, TransformedValue, Error> = fix { adapter in
// use `adapter` to reference the currently created adapter
}
Adapters handle transforming and reverse transforming your models:
let adapter = Adapters.person
var person = Person(name: "Seb", origin: Origin(city: "Berlin"))
var data = adapter.transform(person)
// == .Success(Box([ "name": "Seb", "origin": [ "city_name": "Berlin" ] ]))
adapter.reverseTransform(data.value!)
// == .Success(Box(person))
Both transform
and reverseTransform
return a Result
, which either holds the (reverse) transformed value or an error. This enables you to gracefully handle transformation errors.
Posts
- Working with immutable models in Swift (February 14, 2015)