Swiftpack.co - adam-fowler/jmespath.swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by adam-fowler.
adam-fowler/jmespath.swift 1.0.2
Swift implementation of JMESPath, the JSON query language
⭐️ 35
🕓 2 years ago
.package(url: "https://github.com/adam-fowler/jmespath.swift.git", from: "1.0.2")

JMESPath for Swift

Swift implementation of JMESPath, a query language for JSON. This package is fully compliant with the JMESPath Specification

Usage

Below is a simple example of usage.

import JMESPath

// compile query "a.b"
let expression = try JMESExpression.compile("a.b")
// use query to search json string
let result = try expression.search(json: #"{"a": {"b": "hello"}}"#, as: String.self)
assert(String == "hello")

JMESPath will also use Mirror reflection to search objects already in memory

struct TestObject {
  struct TestSubObject {
      let b: [String]
  }
  let a: TestSubObject
}
// compile query "a.b[1]"
let expression = try JMESExpression.compile("a.b[1]")
let test = TestObject(a: .init(b: ["hello", "world!"]))
// use query to search `test` object
let result = try expression.search(object: test, as: String.self)
assert(result == "world!")

GitHub

link
Stars: 35
Last commit: 34 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v1.0.2
2 years ago

Add Sendable conformance to JMESExpression

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