All Projects → Joannis → Ikigajson

Joannis / Ikigajson

Licence: mit
A high performance JSON library in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Ikigajson

Himotoki
A type-safe JSON decoding library purely written in Swift
Stars: ✭ 786 (+160.26%)
Mutual labels:  json, decoding
Unbox
[Deprecated] The easy to use Swift JSON decoder
Stars: ✭ 1,985 (+557.28%)
Mutual labels:  json, decoding
Json Chunks
streamable json encoder
Stars: ✭ 17 (-94.37%)
Mutual labels:  json, encoder
Json Rust
JSON implementation in Rust
Stars: ✭ 395 (+30.79%)
Mutual labels:  json, encoder
pycayennelpp
A Cayenne Low Power Payload (CayenneLPP) decoder and encoder for Python
Stars: ✭ 17 (-94.37%)
Mutual labels:  encoder, decoding
Encoding
Go package containing implementations of efficient encoding, decoding, and validation APIs.
Stars: ✭ 705 (+133.44%)
Mutual labels:  json, decoding
Gojay
fastest JSON encoder/decoder with powerful stream API for Golang
Stars: ✭ 2,009 (+565.23%)
Mutual labels:  json, encoder
Codability
Useful helpers for working with Codable types in Swift
Stars: ✭ 125 (-58.61%)
Mutual labels:  json, decoding
sms
A Go library for encoding and decoding SMSs
Stars: ✭ 37 (-87.75%)
Mutual labels:  encoder, decoding
Elixir Json
Native JSON library for Elixir
Stars: ✭ 216 (-28.48%)
Mutual labels:  json, decoding
Arrow
🏹 Parse JSON with style
Stars: ✭ 355 (+17.55%)
Mutual labels:  json, decoding
Streaming Json Encoder
PHP library for iteratively encoding large JSON documents piece by piece
Stars: ✭ 260 (-13.91%)
Mutual labels:  json, encoder
Ultrajson
Ultra fast JSON decoder and encoder written in C with Python bindings
Stars: ✭ 3,504 (+1060.26%)
Mutual labels:  json, encoder
Jingo
This package provides the ability to encode golang structs to a buffer as JSON very quickly.
Stars: ✭ 715 (+136.75%)
Mutual labels:  json, encoder
Form
🚂 Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.
Stars: ✭ 454 (+50.33%)
Mutual labels:  decoding, encoder
Jsonlab
JSONLab: a native JSON/UBJSON/MassagePack encoder/decoder for MATLAB/Octave
Stars: ✭ 202 (-33.11%)
Mutual labels:  json, decoding
AnimatedGif
📼 A high performance .NET library for reading and creating animated GIFs
Stars: ✭ 106 (-64.9%)
Mutual labels:  encoder, decoding
Serpent
A protocol to serialize Swift structs and classes for encoding and decoding.
Stars: ✭ 281 (-6.95%)
Mutual labels:  json, decoding
I18n Editor
GUI for editing your i18n translation files
Stars: ✭ 290 (-3.97%)
Mutual labels:  json
Jquery.json Viewer
jQuery plugin for displaying JSON data
Stars: ✭ 295 (-2.32%)
Mutual labels:  json

IkigaJSON

IkigaJSON is a really fast JSON parser. It performed ~4x faster than Foundation in our tests when decoding a type from JSON.

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', '~> 1.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.

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