Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 1.35 KB

README.md

File metadata and controls

71 lines (52 loc) · 1.35 KB

JSON

Fastest JSON implementation written in Swift.

Package.swift

.package(url: "https://github.com/swiftstack/json.git", .branch("dev"))

Usage

Convenience API

let bytes = JSON.encode(Model())
let model = JSON.decode(Model.self, from: bytes)

Streaming API

let output = OutputByteStream()
JSON.encode(Model(), to: output)

let input = InputByteStream(output.bytes)
let model = JSON.decode(Model.self, from: input)

Encoder / Decoder + Streaming API

let bytes = JSONEncoder().encode(Model())
JSONEncoder().encode(Model(), to: stream)
...

JSON Value

public struct JSON {
    public enum Value {
        case null
        case bool(Bool)
        case number(Number)
        case string(String)
        case array([JSON.Value])
        case object([String : JSON.Value])

        public enum Number {
            case int(Int)
            case uint(UInt)
            case double(Double)
        }
    }
}

Performance

{"message":"Hello, World!"}

JSON.JSONEncoder: 934 644 tasks/sec
Foundation.JSONEncoder: 92 619 tasks/sec

JSON.JSONDecoder: 236 062 tasks/sec
Foundation.JSONDecoder: 226 515 tasks/sec

{"message":"\u3053\u3093\u306B\u3061\u306F\u4E16\u754C\uFF01"}

JSON.JSONDecoder: 179 440 tasks/sec
Foundation.JSONDecoder: 88 614 tasks/sec