All Projects β†’ saoudrizwan β†’ Dynamicjson

saoudrizwan / Dynamicjson

Licence: mit
Access JSON properties dynamically like JavaScript using Swift 4.2's new @dynamicMemberLookup feature

Programming Languages

swift
15916 projects
swift4
162 projects

Projects that are alternatives of or similar to Dynamicjson

Userdefaultsstore
Why not use UserDefaults to store Codable objects πŸ˜‰
Stars: ✭ 416 (-38.64%)
Mutual labels:  tvos, watchos
Samkeychain
Simple Objective-C wrapper for the keychain that works on Mac and iOS
Stars: ✭ 5,389 (+694.84%)
Mutual labels:  tvos, watchos
Swiftuipager
Native Pager in SwiftUI
Stars: ✭ 430 (-36.58%)
Mutual labels:  tvos, watchos
Swiftframeworktemplate
A template for new Swift iOS / macOS / tvOS / watchOS Framework project ready with travis-ci, cocoapods, Carthage, SwiftPM and a Readme file
Stars: ✭ 527 (-22.27%)
Mutual labels:  tvos, watchos
Guitar
A Cross-Platform String and Regular Expression Library written in Swift.
Stars: ✭ 641 (-5.46%)
Mutual labels:  tvos, watchos
Efqrcode
A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.
Stars: ✭ 4,121 (+507.82%)
Mutual labels:  tvos, watchos
Gridstack
A flexible grid layout view for SwiftUI
Stars: ✭ 474 (-30.09%)
Mutual labels:  tvos, watchos
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+447.2%)
Mutual labels:  tvos, watchos
Countly Sdk Ios
Countly Product Analytics iOS SDK with macOS, watchOS and tvOS support.
Stars: ✭ 585 (-13.72%)
Mutual labels:  tvos, watchos
Swiftyutils
All the reusable code that we need in each project
Stars: ✭ 490 (-27.73%)
Mutual labels:  tvos, watchos
Json
Micro framework for easily parsing JSON in Swift with rich error messages in less than 100 lines of code
Stars: ✭ 395 (-41.74%)
Mutual labels:  tvos, watchos
Xcake
🍰 Describe Xcode projects in a human readable format and (re)generate one on demand.
Stars: ✭ 549 (-19.03%)
Mutual labels:  tvos, watchos
Impact
Crash capturing library for Apple platforms
Stars: ✭ 395 (-41.74%)
Mutual labels:  tvos, watchos
Waterwheel.swift
The Waterwheel Swift SDK provides classes to natively connect iOS, macOS, tvOS, and watchOS applications to Drupal 7 and 8.
Stars: ✭ 415 (-38.79%)
Mutual labels:  tvos, watchos
Sentry Cocoa
The official Sentry SDK for iOS, tvOS, macOS, watchOS
Stars: ✭ 370 (-45.43%)
Mutual labels:  tvos, watchos
Stringz
A lightweight and powerful editor for localizing iOS, macOS, tvOS, and watchOS applications.
Stars: ✭ 440 (-35.1%)
Mutual labels:  tvos, watchos
Solarized Dark For Xcode
Solarized Dark Theme for Xcode. Compatible with all modern versions of Xcode since 2013!
Stars: ✭ 358 (-47.2%)
Mutual labels:  tvos, watchos
Valet
Valet lets you securely store data in the iOS, tvOS, or macOS Keychain without knowing a thing about how the Keychain works. It’s easy. We promise.
Stars: ✭ 3,712 (+447.49%)
Mutual labels:  tvos, watchos
Corexlsx
Excel spreadsheet (XLSX) format parser written in pure Swift
Stars: ✭ 481 (-29.06%)
Mutual labels:  tvos, watchos
Flint
The Flint framework for building apps on Apple platforms using Feature Driven Development
Stars: ✭ 636 (-6.19%)
Mutual labels:  tvos, watchos

DynamicJSON


GitRoyalty Platform: iOS, macOS, watchOS, tvOS Language: Swift 4.2 License: MIT

Installation β€’ Usage β€’ License

DynamicJSON is a dynamically typed JSON parser built upon the new @dynamicMemberLookup feature introduced by Chris Lattner in Swift 4.2. This allows us to access arbitrary object members which are resolved at runtime, allowing Swift to be as flexible as JavaScript when it comes to JSON.

Before

if let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
   let user = jsonObject["user"] as? [String: Any],
   let username = user["username"] as? String {
	// ...
}

After

let username = JSON(data).user.username.string

Installation

Support DynamicJSON's contributors with a monthly subscription on https://gitroyalty.com/saoudrizwan/DynamicJSON to install this package.

Subscribe on GitRoyalty
* comes with a 2 week free trial and can be cancelled anytime

Usage

1. Initialize 🐣

Throw Anything into a JSON object to get started

let json = JSON(Data())
           JSON(123)
           JSON(["key": "value"])
           JSON(["element", 1])
           JSON("Hello world")
           JSON(false)

...or cast a literal as JSON

let json = "Hello world" as JSON
           123 as JSON
           [1, 2, 3] as JSON

let user: JSON = [
	"username": "Saoud",
	"age": 21,
	"address": [
	    "zip": "12345",
	    "city": "San Diego"
	]
]

2. Drill in ⛏

Treat JSON objects like you're in JavaScript Land

let dictionary = json.dictionary
let array = json[0].cars.array
let string = json.users[1].username.string
let nsnumber = json.creditCard.pin.number
let double = json[3][1].height.double
let int = json[0].age.int
let bool = json.biography.isHuman.bool

Note how JSON doesn't actually have properties like cars or users, instead it uses dynamic member lookup to traverse through its associated JSON data to find the object you're looking for.

In case you have a key that's an actual property of JSON, like number or description for example, just use the string subscript accessor like so:

let number = json.account.contact["number"].number
let description = json.user.biography["description"].string

3. Have fun πŸ€ͺ

JSON conforms to Comparable

let json1 = JSON(jsonData1)
let json2 = JSON(jsonData2)

// Equality applies to all types (Dictionary, Array, String, NSNumber, Bool, NSNull)
let isEqual = json1 == json2

// Less/greater than only applies to NSNumbers (Double, Int) and Strings
let isLessThan = json1 < json2
let isLessThanOrEqual = json1 <= json2
let isGreaterThan = json1 > json2
let isGreaterThanOrEqual = json1 >= json2

Pretty print for debug purposes

print(json)

Convert to raw object

let anyObject = json.object

Convert to Data

let data = json.data() // optionally specify options...

License

DynamicJSON uses the MIT license. Please file an issue if you have any questions or if you'd like to share how you're using DynamicJSON.

Contribute

DynamicJSON is in its infancy, but provides the barebones of a revolutionary new way to work with JSON in Swift. Please feel free to send pull requests of any features you think would add to DynamicJSON and its philosophy.

Questions?

Contact me by email [email protected], or by twitter @sdrzn. Please create an issue if you come across a bug or would like a feature to be added.

Notable Mentions

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