Gloss is a shiny, new JSON parsing library written in Swift!
Gloss enables simple transformation from JSON to objects - and from objects back to JSON. It supports nested models with no extra work, as well as custom transformations.
Let’s take a quick look using the following JSON representing a Github repository.
Creating a Repo object:
Translating a Repo object back to JSON:
There’s a whole lot more info in the Gloss docs - including a closer look at these models, how to create custom transformations, and more.
Gloss joins several Swift JSON parsing libraries - why create a new one?
After reviewing several other libraries, there were aspects of each that I liked and those I did not. I tried to address the following concerns with Gloss:
Immutable models - I don’t want to require each property to be a var
Serialization - I want a library that offers not just translation from JSON, but back to JSON
Ease of model creation - I want my models to be fairly compact, with a roughly 1-line-to-property ratio for deserialization and serialization respectively
Ease of comprehension - I want a library that’s not too difficult to understand if I need to dive into the source code
Additionally, I’d say there’s not a clear call on which JSON library is the go-to - so there’s still room to introduce new takes on the issue at hand.
I also just love the act of contributing to collective knowledge and utility by open sourcing libraries like this, especially one with such potential for impact.
Gloss is available via Cocoapods - just add the following to your Podfile:
As you’re vetting libraries to use for JSON parsing in your next Swift project or if you’re looking to switch libraries - give Gloss a try!
This blog is licensed under Attribution-Noncommercial-Share Alike 3.0 Unported license.
comments powered by Disqus