Giter Club home page Giter Club logo

jay's Introduction

Jay

Build Status Latest Release Platforms Package Managers

Blog Twitter Czechboy0

Pure-Swift JSON parser & formatter. Fully streamable input and output. Linux & OS X ready. Replacement for NSJSONSerialization.

Jay conforms to the following specifications:

For extra convenience functions when working with the JSON enum, check out Jay-Extras.

โ“ Why?

We all use JSON. Especially when writing server-side Swift that needs to run on Linux. #0dependencies

This is my take on how a JSON parser should work. This is not another JSON mapping utility library. This is an actual JSON parser and formatter. Check out the code, it was fun to write ๐Ÿ˜‡

Features

  • Parsing: data -> JSON object
  • Formatting: JSON object -> data
  • Pretty printing
  • Streaming input and output, low memory footprint

Usage

Parsing from data (deserialization)

do {
	//get data from disk/network
	let data: [UInt8] = ...

	//ask Jay to parse your data
	let json = try Jay().jsonFromData(data) // JSON
	//or
	let json = try Jay().anyJsonFromData(data) // [String: Any] or [Any]

	//if it doesn't throw an error, all went well
	if let tasks = json.dictionary?["today"]?.array {
	    //you have a dictionary root object, with an array under the key "today"
	    print(tasks) //["laundry", "cook dinner for gf"]
	} 
} catch {
	print("Parsing error: \(error)")
}

Formatting into data (serialization)

do {
	//get a json object (works for both [String: Any] and typesafe versions - JSON)

	//ask Jay to generate data
	let anyContainer = ... // [String: Any] or [Any]
	let data = try Jay(formatting: .prettified).dataFromJson(any: json) // [UInt8]
	//or
	let json: JSON = ... // JSON
	let data = try Jay(formatting: .prettified).dataFromJson(json: json) // [UInt8]

	//send data over network, save to disk
} catch {
	print("Formatting error: \(error)")
}

Installation

Swift Package Manager

.Package(url: "https://github.com/czechboy0/Jay.git", majorVersion: 0, minor: 16)

๐Ÿ’™ Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

๐Ÿ’ Contributing

Please create an issue with a description of your problem or open a pull request with a fix.

โœŒ๏ธ License

MIT

๐Ÿ‘ฝ Author

Honza Dvorsky - http://honzadvorsky.com, @czechboy0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.