All Projects → hkellaway → Gloss

hkellaway / Gloss

Licence: mit
[Deprecated] A shiny JSON parsing library in Swift ✨ Loved by many from 2015-2021

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Gloss

Unbox
[Deprecated] The easy to use Swift JSON decoder
Stars: ✭ 1,985 (+20.45%)
Mutual labels:  json, json-parsing
Jsonwatch
Track changes in JSON data from the command line
Stars: ✭ 130 (-92.11%)
Mutual labels:  json
Scobot
SCORM API for Content. JavaScript library, QUnit tests and examples.
Stars: ✭ 128 (-92.23%)
Mutual labels:  json
Nano
Lightweight, facility, high performance golang based game server framework
Stars: ✭ 1,888 (+14.56%)
Mutual labels:  json
Protostuff
Java serialization library, proto compiler, code generator
Stars: ✭ 1,730 (+4.98%)
Mutual labels:  json
Fossurl
Your Own Url Shortner Without any fancy server side processing and support for custom url , which can even be hosted on GitHub Pages
Stars: ✭ 131 (-92.05%)
Mutual labels:  json
Tiny Json
The tiny-json is a versatile and easy to use json parser in C suitable for embedded systems. It is fast, robust and portable.
Stars: ✭ 127 (-92.29%)
Mutual labels:  json
Httpexpect
End-to-end HTTP and REST API testing for Go.
Stars: ✭ 1,821 (+10.5%)
Mutual labels:  json
Pyjson tricks
Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable.
Stars: ✭ 131 (-92.05%)
Mutual labels:  json
Elementui
Generate a form using JSON Schema, Vue and ElementUI
Stars: ✭ 130 (-92.11%)
Mutual labels:  json
Restapimvvm
App that interacts with a Rest Api. Architecture is MVVM.
Stars: ✭ 130 (-92.11%)
Mutual labels:  json
Sabisu Rails
Simple and powerful engine for exploring your Rails api application
Stars: ✭ 129 (-92.17%)
Mutual labels:  json
Quicktype Vscode
VS Code extension to convert JSON to TypeScript, C#, Go, and many more
Stars: ✭ 131 (-92.05%)
Mutual labels:  json
Jsonviewer
Android json viewer, to convert json strings to a friendly readable format, it supports expend&collapsed json strings.
Stars: ✭ 129 (-92.17%)
Mutual labels:  json
Oq
A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
Stars: ✭ 132 (-91.99%)
Mutual labels:  json
Any Json
Convert (almost) anything to JSON
Stars: ✭ 128 (-92.23%)
Mutual labels:  json
Freetakserver
an open source, lightweight Server for connect TAK clients
Stars: ✭ 127 (-92.29%)
Mutual labels:  json
Borer
Efficient CBOR and JSON (de)serialization in Scala
Stars: ✭ 131 (-92.05%)
Mutual labels:  json
Quicktype Xcode
Xcode extension to paste JSON as Swift, Objective-C, and more
Stars: ✭ 1,656 (+0.49%)
Mutual labels:  json
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (-91.99%)
Mutual labels:  json

Gloss

🚨 Deprecation Notice 🚨

Gloss has been deprecated in favor of Swift's Codable framework.

The existing Gloss source is not going away, however updates will only be made to support migration to Codable. Read the MIGRATION GUIDE now to get started.

If you do not yet have any Gloss models in your project yet are considering it for JSON parsing, turn around now! Select Swift's Codable framework instead.

I understand, I'm Using Gloss Anyway

Swift version CocoaPods Carthage compatible SPM CocoaPods Build Status

See the former README.md on instructions for using Gloss pre-Codable migration.

Credits

Gloss was created by Harlan Kellaway

Thank you to all contributors and the Swift community for 5 years of Gloss! 💖

License License

See the LICENSE file for more info.

Codable Migration Quick Reference

The following is a reference for what your Gloss models and call-sites should look like after preparing to migrate to Codable.

See the MIGRATION GUIDE for more detail.

Version

Use version 3.2.0 or higher to take advantage of migration helpers.

Deserialization

Given a Gloss model that conforms to JSONDecodable, add conformance to Decodable. A model that looks like this:

import Gloss

struct MyModel: JSONDecodable {
    let id: Int?
    
    init?(json: JSON) {
        self.id = "id" <~~ json
    }
}

adds

extension MyModel: Decodable {

    init(from decoder: Swift.Decoder) throws {
        // Proper Decodable definition or throw GlossError.decodableMigrationUnimplemented
        // Remove this method if Codable can synthesize decoding for you
    }

}

Initializing a Model from JSON

Where initializing that model currently looks like:

let myModel = MyModel(json: someJSON)

it becomes:

let myModel: MyModel = .from(decodableJSON: someJSON)

Serialization

Given a Gloss model that conforms to JSONEncodable, add conformance to Encodable. A model that looks like this:

import Gloss

struct MyModel: JSONEncodable {
    let id: Int?
    
    func toJSON() -> JSON? {
        return jsonify(["id" ~~> self.id])
    }
}

adds

extension MyModel: Encodable {

    func encode(to encoder: Swift.Encoder) throws {
        // Proper Encodable defintion or throw GlossError.encodableMigrationUnimplemented
        // Remove this method if Codable can synthesize encoding for you
    }

}

Translating Model Objects to JSON

Where translating to JSON currently looks like this:

let json: JSON? = myModel.toJSON()

it becomes:

let json: JSON? = myModel.toEncodableJSON()

JSON Arrays

Similar usage applies to arrays of Decodable and Encodable models, with from(decodableJSONArray:) and toEncodableJSONArray() respectively.

Configuring JSONDecoder and JSONEncoder

If your Codable definitions are sound but you're encountering Codable errors, make sure your JSONDecoder or JSONEncoder instances are configured properly and pass them at call-sites:

let mySharedJSONDecoder: JSONDecoder = ...
let myModel: MyModel = .from(decodableJSON: someJSON, jsonDecoder: mySharedJSONDecoder)
let mySharedJSONEncoder: JSONEncoder = ...
let json: JSON? = myModel.toEncodableJSON(jsonEncoder: mySharedJSONEncoder)

Using Data Instead of JSON to Create Models

In the places where you've come to rely on Gloss's JSON type, you'll eventually need to pass Data, as that is what Codable uses. To get a jump using decode(:), one option is use the same method Gloss uses to do Data transformation:

import Gloss

let sharedGlossSerializer: GlossJSONSerializer = ...
let json: JSON = ...
if let data: Data? = sharedGlossSerializer.data(from: json, options: nil) {
    let myModel: MyModel = try? myJSONDecoder.decode(MyModel.self, from : data)
    ...
}

Take the opportunity with this migration to pare your models down to the slim amount of code Codable needs to work its magic and detangle your networking code from the details of JSON serialization. Future you will be grateful! 🔮

EOF

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].