Swiftpack.co - nchlscs/swift-json as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nchlscs.
nchlscs/swift-json 0.3.0
Handle JSON in Swift dynamically
⭐️ 0
🕓 5 weeks ago
.package(url: "https://github.com/nchlscs/swift-json.git", from: "0.3.0")

Swift JSON

swift-json is a dynamic wrapper around JSON decoders that uses @dynamicMemberLookup and @dynamicCallable features to access values from JSON data.


This is useful for accessing specific values from JSON data when you want to skip over unwanted boilerplate abstractions. For instance, we have the following fragment, and the longitude value is all we are interested in:

let data = """
    "address": {
      "city": "Stockholm",
      "geo": {
        "latitude": 59.2,
        "longitude": 18.04
  .data(using: .utf8)!

To achieve this with JSONDecoder, we need to populate the following structs:

import Foundation

struct Response: Decodable {
  let address: Address

struct Address: Decodable {
  let geo: Geo

struct Geo: Decodable {
  let longitude: Double

let longitude = try JSONDecoder()
  .decode(Response.self, from: data)

// Prints 18.04

With swift-json it would be:

import JSON

let longitude: Double = try JSON(data)

// Prints 18.04

More examples

See tests


Swift Package Manager

.package(url: "https://github.com/nchlscs/swift-json", from: "0.3.0")


Stars: 0
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics