jmespath.swift

1.0.2

Swift implementation of JMESPath, the JSON query language
adam-fowler/jmespath.swift

What's New

v1.0.2

2022-02-26T12:28:06Z

Add Sendable conformance to JMESExpression

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!")

Description

  • Swift Tools 5.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Mar 24 2024 03:21:41 GMT-0900 (Hawaii-Aleutian Daylight Time)