Introducing Gloss ✨

Gloss allows you to easily translate JSON to models and back. And it's written in Apple's newest language innovation, Swift!

Translating JSON to models

Given the following JSON:

  "id" : 5456481,
  "login" : "hkellaway"

We can create the following simple Gloss model, that can be initialized by passing in such JSON:

import Gloss

struct RepoOwner: Decodable {

    let ownerId: Int?
    let username: String?

    // MARK: - Deserialization

    init?(json: JSON) {
        self.ownerId = "id" <~~ json
        self.username = "login" <~~ json
Piece of cake! 🍰

See: Deserialization, Non-Optional Properties, Initializing Model Objects

Translating Models to JSON

Gloss allows translating from models to JSON as well. Given the previous model, we can:

import Gloss

struct RepoOwner: Glossy {

    let ownerId: Int?
    let username: String?

    // MARK: - Deserialization
    // ...

    // MARK: - Serialization

    func toJSON() -> JSON? {
        return jsonify([
            "id" ~~> self.ownerId,
            "login" ~~> self.username

No sweat! 😅

See: Serialization, Model Objects to JSON

And More

Gloss extends beyond these basic features, allowing custom transformations and handling of translation from/to JSON arrays. 💥

See: JSON Arrays, Transforming Dates, Custom Transformations

Why Gloss?

Gloss joins many other JSON parsing libraries in Swift; but, tries to solve the same problem with specific pain points in mind:

Open Source

Gloss is open source and readily accepts contributions from the community 💖.

Being open source both makes Gloss a better library by combining many developers skills and needs, and allows it to serve as a learning tool.

Have a question or issue? Join Gloss's development on Github.