Skip to content

JSON written in Swift with Stream/Codable support

License

Notifications You must be signed in to change notification settings

swiftstack/json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

JSON written in Swift with Stream/Codable support

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published