All Projects → orlandos-nl → IkigaJSON

orlandos-nl / IkigaJSON

Licence: MIT License
A high performance JSON library in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to IkigaJSON

Xmlcoder
Easy XML parsing using Codable protocols in Swift
Stars: ✭ 460 (+45.57%)
Mutual labels:  encoder, decoder, codable
Codable Diy Kit
A template for creating your own Swift Codable encoders and decoders
Stars: ✭ 207 (-34.49%)
Mutual labels:  encoder, decoder, codable
Codablecsv
Read and write CSV files row-by-row or through Swift's Codable interface.
Stars: ✭ 214 (-32.28%)
Mutual labels:  encoder, decoder, codable
AnimatedGif
📼 A high performance .NET library for reading and creating animated GIFs
Stars: ✭ 106 (-66.46%)
Mutual labels:  encoder, decoder
bytecodec
A tiny Rust framework for implementing encoders/decoders of byte-oriented protocols
Stars: ✭ 21 (-93.35%)
Mutual labels:  encoder, decoder
png pong
A pure Rust PNG image decoder and encoder based on lodepng.
Stars: ✭ 21 (-93.35%)
Mutual labels:  encoder, decoder
rmarsh
Ruby Marshal 4.8 encoder/decoder in Golang. Why? Who knows.
Stars: ✭ 15 (-95.25%)
Mutual labels:  encoder, decoder
otfed
An OpenType font format encoder & decoder written in OCaml
Stars: ✭ 15 (-95.25%)
Mutual labels:  encoder, decoder
keystore-go
A Go (golang) implementation of Java KeyStore encoder/decoder
Stars: ✭ 119 (-62.34%)
Mutual labels:  encoder, decoder
schifra
C++ Reed Solomon Error Correcting Library https://www.schifra.com
Stars: ✭ 28 (-91.14%)
Mutual labels:  encoder, decoder
pytextcodifier
📦 Turn your text files into codified images or your codified images into text files.
Stars: ✭ 14 (-95.57%)
Mutual labels:  encoder, decoder
logfmt
Package logfmt marshals and unmarshals logfmt messages.
Stars: ✭ 156 (-50.63%)
Mutual labels:  encoder, decoder
urlpack
Pure JavaScript toolkit for data URLs (MessagePack, Base58 and Base62)
Stars: ✭ 51 (-83.86%)
Mutual labels:  encoder, decoder
png
🖼A full-featured PNG decoder and encoder.
Stars: ✭ 64 (-79.75%)
Mutual labels:  encoder, decoder
sms
A Go library for encoding and decoding SMSs
Stars: ✭ 37 (-88.29%)
Mutual labels:  encoder, decoder
online-ethereum-abi-encoder-decoder
A quick online tool to abi-encode and abi-decode constructor arguments used in ethereum's solidity. https://adibas03.github.io/online-ethereum-abi-encoder-decoder/
Stars: ✭ 37 (-88.29%)
Mutual labels:  encoder, decoder
audio
Audio support for Go language.
Stars: ✭ 62 (-80.38%)
Mutual labels:  encoder, decoder
android-opus-codec
Implementation of Opus encoder and decoder in C++ for android with JNI
Stars: ✭ 44 (-86.08%)
Mutual labels:  encoder, decoder
aiff
Battle tested aiff decoder/encoder
Stars: ✭ 20 (-93.67%)
Mutual labels:  encoder, decoder
Enmime
MIME mail encoding and decoding package for Go
Stars: ✭ 246 (-22.15%)
Mutual labels:  encoder, decoder

IkigaJSON

IkigaJSON is a really fast JSON parser. It performed ~4x faster than Foundation in our tests when decoding a type from JSON. Aside from being more performant, IkigaJSON has a much lower and more stable memory footprint, too!

Join our Discord for any questions and friendly banter.

Server-Side Swift

The above statement was tested on Foundation for macOS and iOS. If you're using Swift on Linux with Swift 5.5, your performance is slightly better if you use the new Foundation for Linux. Swift 5.5 does not improve Foundation's JSON performance on macOS or iOS.

Adding the dependency

The 1.x versions are reliant on SwiftNIO 1.x, and for SwiftNIO 2.x support use the 2.x versions of IkigaJSON.

SPM:

.package(url: "https://github.com/Ikiga/IkigaJSON.git", from: "1.0.0"),
// Or, for SwiftNIO 2
.package(url: "https://github.com/Ikiga/IkigaJSON.git", from: "2.0.0"),

Cocoapods:

pod 'IkigaJSON', '~> 1.0'
# Or, for SwiftNIO 2
pod 'IkigaJSON', '~> 2.0'

Usage

import IkigaJSON

struct User: Codable {
    let id: Int
    let name: String
}

let data = Data()
var decoder = IkigaJSONDecoder()
let user = try decoder.decode(User.self, from: data)

In Vapor 4

Conform Ikiga to Vapor 4's protocols like so:

extension IkigaJSONEncoder: ContentEncoder {
    public func encode<E: Encodable>(
        _ encodable: E,
        to body: inout ByteBuffer,
        headers: inout HTTPHeaders
    ) throws {
        headers.contentType = .json
        try self.encodeAndWrite(encodable, into: &body)
    }
}

extension IkigaJSONDecoder: ContentDecoder {
    public func decode<D: Decodable>(
        _ decodable: D.Type,
        from body: ByteBuffer,
        headers: HTTPHeaders
    ) throws -> D {
        guard headers.contentType == .json || headers.contentType == .jsonAPI else {
            throw Abort(.unsupportedMediaType)
        }
        
        return try self.decode(D.self, from: body)
    }
}

Register the encoder/decoder to Vapor like so:

var decoder = IkigaJSONDecoder()
decoder.settings.dateDecodingStrategy = .iso8601
ContentConfiguration.global.use(decoder: decoder, for: .json)

var encoder = IkigaJSONEncoder()
encoder.settings.dateDecodingStrategy = .iso8601
ContentConfiguration.global.use(encoder: encoder, for: .json)

Raw JSON

IkigaJSON supports raw JSON types (JSONObject and JSONArray) like many other libraries do, alongside the codable API described above. The critical difference is that IkigaJSON edits the JSON inline, so there's no additional conversion overhead from Swift type to JSON.

var user = JSONObject()
user["username"] = "Joannis"
user["roles"] = ["admin", "moderator", "user"] as JSONArray
user["programmer"] = true

print(user.string)

print(user["username"].string)
// OR
print(user["username"] as? String)

SwiftNIO support

The encoders and decoders support SwiftNIO.

var user = try JSONObject(buffer: byteBuffer)
print(user["username"].string)

We also have added the ability to use the IkigaJSONEncoder and IkigaJSONDecoder with JSON.

let user = try decoder.decode([User].self, from: byteBuffer)
var buffer: ByteBuffer = ...

try encoder.encodeAndWrite(user, into: &buffer)

The above method can be used to stream multiple entities from a source like a database over the socket asynchronously. This can greatly reduce memory usage.

Performance

By design you can build on top of any data storage as long as it exposes a pointer API. This way, IkigaJSON doesn't (need to) copy any data from your buffer keeping it lightweight. The entire parser can function with only 1 memory allocation and allows for reusing the Decoder to reuse the memory allocation.

This allocation (called the JSONDescription) acts as a filter over the original dataset, indicating to IkigaJSON where keys, values and objects start/end. Therefore IkigaJSON can do really fast inline mutations, and provide objects such as JSONObject/JSONDescription that are extremely performant at reading individual values. This also allows IkigaJSON to decode from its own helper types such as JSONObject and JSONArray, since it doesn't need to regenerate a JSONDescription and has the original buffer at hand.

Support

  • All decoding strategies that Foundation supports
  • Unicode
  • Codable
  • Escaping
  • Performance 🚀
  • Date/Data encoding strategies
  • Raw JSON APIs (non-codable)
  • Codable decoding from JSONObject and JSONArray
  • \u escaped unicode characters

TODO:

  • JSON error accumulation
  • Lightweight JSON inline comparison helpers

Media

Architecture

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].