All Projects → tyrone-sudeium → Jsoncore

tyrone-sudeium / Jsoncore

Licence: mit
A Swift JSON parser that doesn't need Objective-C bridging and doesn't depend on Foundation

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Jsoncore

SwiftMC
A Minecraft server and proxy written from scratch in Swift.
Stars: ✭ 22 (-74.42%)
Mutual labels:  swift-package-manager, server-side-swift
Mongo Swift Driver
The official MongoDB driver for Swift
Stars: ✭ 242 (+181.4%)
Mutual labels:  server-side-swift, swift-package-manager
BetterMappable
Better Mappable through Property Wrappers using ObjectMapper
Stars: ✭ 26 (-69.77%)
Mutual labels:  swift-package-manager, json-parser
Telegrammer
Telegram Bot - written with Swift 5.2 / NIO, supports Linux, macOS
Stars: ✭ 248 (+188.37%)
Mutual labels:  server-side-swift, swift-package-manager
Firebaseswift
Firebase REST API wrapper for use in server-side Swift
Stars: ✭ 54 (-37.21%)
Mutual labels:  server-side-swift, swift-package-manager
Dictfier
Python library to convert/serialize class instances(Objects) both flat and nested into a dictionary data structure. It's very useful in converting Python Objects into JSON format
Stars: ✭ 67 (-22.09%)
Mutual labels:  json-parser
Dikit
Dependency Injection Framework for Swift, inspired by KOIN.
Stars: ✭ 77 (-10.47%)
Mutual labels:  swift-package-manager
Burritos
A collection of Swift Property Wrappers (formerly "Property Delegates")
Stars: ✭ 1,139 (+1224.42%)
Mutual labels:  swift-package-manager
Variable Injector
Continuous Integration Tool for Swift Projects
Stars: ✭ 63 (-26.74%)
Mutual labels:  swift-package-manager
Statefultabview
A SwiftUI TabView that retains the state of each tab as well as some other goodies.
Stars: ✭ 83 (-3.49%)
Mutual labels:  swift-package-manager
Vapor Clean
A Vapor 3 template with no additional cruft.
Stars: ✭ 80 (-6.98%)
Mutual labels:  server-side-swift
Dtgradientbutton
Easy way to set gradient background to your buttons.
Stars: ✭ 76 (-11.63%)
Mutual labels:  swift-package-manager
Aws
Swift wrapper around AWS API
Stars: ✭ 67 (-22.09%)
Mutual labels:  server-side-swift
Spasibo
🙏 Support your favourite open source projects
Stars: ✭ 78 (-9.3%)
Mutual labels:  swift-package-manager
Zzzjson
The fastest JSON parser written in pure C
Stars: ✭ 66 (-23.26%)
Mutual labels:  json-parser
Dtoverlaycontroller
A customizable and easy-to-use overlay view controller container.
Stars: ✭ 82 (-4.65%)
Mutual labels:  swift-package-manager
Cameramanager
Simple Swift class to provide all the configurations you need to create custom camera view in your app
Stars: ✭ 1,130 (+1213.95%)
Mutual labels:  swift-package-manager
Loadingshimmer
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
Stars: ✭ 1,180 (+1272.09%)
Mutual labels:  swift-package-manager
Swiftlinkpreview
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
Stars: ✭ 1,216 (+1313.95%)
Mutual labels:  swift-package-manager
Fhirmodels
Swift library for FHIR® resource data models
Stars: ✭ 71 (-17.44%)
Mutual labels:  swift-package-manager

JSON Core

Build Status

Project Discontinued!

Well everyone, it was fun while it lasted! As of Swift 4, the JSON situation is vastly improved, and there's very little practical reason to use JSONCore any more! Please adopt the official Swift Codable protocol and use the built-in encoder and decoder.

See the Apple documentation of Codable for more information.

JSONCore will not be updated for Swift 4 and it will not receive any future development.

Introduction

JSON Core is a JSON parser and serializer written using only core Swift. This means it has no dependencies on Foundation, UIKit, AppKit or even Darwin. This is a true parser and serializer, it doesn't use NSJSONSerialization at all, nor does it call out to any C JSON library.

It requires at least Xcode 8 and Swift 3. If you need Swift 2.x support, use the 1.0.0 tag.

Why?

Performance

The Swift - Objective-C bridge is very efficient for the most part. However, when dealing with potentially millions of object allocations, passing them back and forth through the bridge is extremely costly. This is completely unnecessary busywork for the CPU and is just a side effect of the fact that the standard JSON engine for Swift today is an Objective-C class, NSJSONSerialization, which returns Objective-C objects.

JSON Core works only on native Swift types, Array, Dictionary, Int64, Double, and Bool, which means there's no bridging required. It's still a long way off being as efficient as NSJSONSerialization in Objective-C only mode, but it's already considerably faster than NSJSONSerialization when used with Swift code.

Here's a chart showing the performance characteristics of JSON Core when parsing an extremely large JSON file from disk. The source JSON file is generated when running the unit test and contains an array of one million JSON objects. The file is approximately 212MB.

Chart

Over time I'd like to improve this but at the moment I'm limited mostly by the performance of Dictionary. It's extremely costly to build up a Dictionary by creating an empty one and then setting values and keys manually, but as of Swift 2.1, there's no other way to create a Dictionary dynamically. In Foundation / CoreFoundation it's possible to very quickly create an NSDictionary using a C array of values and keys. Unless I write my own data structure to represent JSON objects, which means giving up the advantages of simply returning a Swift Dictionary to the caller, I'm probably not going to get a huge amount more performance.

Be aware that if the string you pass in to JSONParser.parseData was bridged using an NSString constructor, there'll be serious performance ramifications. You should be aware of what's constructing your raw JSON data object and how it gets initialised. You'll get an almost 2x speed boost by sticking to String over NSString.

Usage

let json = "{\"test\": 1}"
do {
    let value = try JSONParser.parse(string: json)
    // value is a JSONValue enum, which for our JSON should be
    // an Object/Dictionary
    guard let test = value["test"]?.int else { return }
    print("test is \(test)")
} catch let err {
    if let printableError = err as? CustomStringConvertible {
        print("JSON parse error: \(printableError)")
    }
}

Installation

###via Swift Package Manager (Swift 3) To use JSONCore as a Swift Package Manager package just add the following in your Package.swift file.

import PackageDescription

let package = Package(
    name: "HelloWorld",
    dependencies: [
        .Package(url: "https://github.com/tyrone-sudeium/JSONCore.git", majorVersion: 2))
    ]
)

###via Carthage To use JSONCore with Carthage add You can use Carthage to install JSONCore add the following lines to your Carthage:

github "tyrone-sudeium/JSONCore"

###via Cocoapods I'm not on CocoaPods (yet!), however, I will add support for CocoaPods when I'm happy JSON Core is stable enough for production use.

###Manual JSON Core is just a single Swift file with zero dependencies, so feel free to make this repo a submodule and just drop the JSONCore.swift file into your project directly.

Other JSON Libraries

If you hate something, or everything about JSON Core, the Swift community has you covered with plenty of alternatives.

Just want the fastest parser around?

Want something quick but also does interesting things like lazy sequences?

Just want something popular?

I won't take it personally.

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