The State of JSON Address
We’re looking around for new and/or notable and/or actively maintained developments in the JSON + Swift world. You always enjoy a good treasure hunt, don’t you?
Join the DZone community and get the full member experience.Join For Free
So this weekend we’re taking a look at a weather API service that provides data in JSON. So we’re looking around for new and/or notable and/or actively maintained developments in the JSON + Swift world. You always enjoy a good treasure hunt, don’t you?
One particularly nifty thing we stumbled across is JSONExport, which isn’t that new but was to us. If it’s new to you too, check it out:
JSONExport is a desktop application for Mac OS X written in Swift. Using JSONExport you will be able to:
- Convert any valid JSON object to a class of one of the currently supported languages.
- Preview the generated content before saving it.
- Include constructors only, utility methods only, both or none.
- Change the root class name.
- Set a class name prefix for the generated classes.
- Set package name for Java files.
And you have a baker’s dozen options of output for that:
- Java for Android.
- Java for Android – to use with Realm.
- Swift Classes.
- Swift Classes – To use with SwiftyJSON library.
- Swift Classes – To use with Realm.
- Swift – Core Data.
- Swift Structures.
- Swift – Struct – Gloss
- Objective-C – iOS.
- Objective-C – Mac.
- Objective-C – Core Data.
- Objective-C – To use with Realm.
- Swift – Mappable [not included in README — ed.]
Convenient! Or perhaps you’d like to handle Core Data serialization more directly? Here’s an option:
Groot: “From JSON to Core Data and back.”
Groot provides a simple way of serializing Core Data object graphs from or into JSON.
Groot uses annotations in the Core Data model to perform the serialization and provides the following features:
- Attribute and relationship mapping to JSON key paths.
- Value transformation using named NSValueTransformer objects.
- Object graph preservation.
- Support for entity inheritance
Or here’s another option:
Sync: “ Modern Swift JSON synchronization to Core Data.”
Sync eases your everyday job of parsing a JSON response and getting it into Core Data. It uses a convention-over-configuration paradigm to facilitate your workflow.
- Automatic mapping of CamelCase or snake_case JSON into Core Data
- Handles operations in safe background threads
- Thread-safe saving, we handle retrieving and storing objects in the right threads
- Diffing of changes, updated, inserted and deleted objects (which are automatically purged for you)
- Auto-mapping of relationships (one-to-one, one-to-many and many-to-many)
- Smart-updates, only updates your NSManagedObjects if the server values are different (useful when using NSFetchedResultsController delegates)
- Uniquing, Core Data does this based on objectIDs, we use your primary key (such as id) for this
- NSOperation subclass, any Sync process can be queued and cancelled at any time!
If you’re just looking for JSON parsing into objects without the Core Data integration, there’s … a surprising number of helper options these days:
- AlamofireJsonToObjects: “An Alamofire extension which converts JSON…”
- Bric-à-brac: “Complete JSON toolkit for Swift”
- Freddy: “A reusable framework for parsing JSON in Swift.”
- Gloss: “A shiny JSON parsing library in Swift.”
- JASON: “Fast JSON parsing for Swift.”
- Jay: “Pure-Swift JSON parser & formatter…”
- JSONCodable: “Hassle-free JSON encoding and decoding in Swift.”
- JSONJoy-Swift “Convert JSON to Swift objects.”
- Mapper: “A JSON deserialization library for Swift.”
- OCMapper “Objective-C & Swift library to easily map NSDictionary to model objects…”
- ObjectMapper: “Simple JSON Object mapping written in Swift.”
- PMJSON: “Pure Swift JSON encoding/decoding library.”
- PureJsonSerializer: “A pure-Swift JSON serializer and deserializer”
- SwiftyJSON: “The better way to deal with JSON data in Swift.”
- Unbox: “The easy to use Swift JSON decoder.”
Some discussions to help you decide which of these if any suits your particular use case best:
Enjoy your paradox of choice!
Published at DZone with permission of Alex Curylo, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.