Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

The State of JSON Address

DZone's Guide to

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?

· Integration Zone
Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

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:

  1. Java for Android.
  2. Java for Android – to use with Realm.
  3. Swift Classes.
  4. Swift Classes – To use with SwiftyJSON library.
  5. Swift Classes – To use with Realm.
  6. Swift – Core Data.
  7. Swift Structures.
  8. Swift – Struct – Gloss
  9. Objective-C – iOS.
  10. Objective-C – Mac.
  11. Objective-C – Core Data.
  12. Objective-C – To use with Realm.
  13. 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:

  1. Attribute and relationship mapping to JSON key paths.
  2. Value transformation using named NSValueTransformer objects.
  3. Object graph preservation.
  4. 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:

… and a veritable plethora of others. If we and all those collections missed your favorite, let us know!

Some discussions to help you decide which of these if any suits your particular use case best:

How I deal with JSON in Swift

Everything You Need to Know About JSONJoy, SwiftyJSON & OCMapper

Swift JSON Shoot-Out

The state of JSON parsing in Swift – Part 1

Enjoy your paradox of choice!

Related Refcard:

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

Topics:
ios ,swift ,json

Published at DZone with permission of Alex Curylo, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}