Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adam-fowler/jmespath.swift
Swift implementation of JMESPath, the JSON query language
https://github.com/adam-fowler/jmespath.swift
jmespath json swift
Last synced: 13 days ago
JSON representation
Swift implementation of JMESPath, the JSON query language
- Host: GitHub
- URL: https://github.com/adam-fowler/jmespath.swift
- Owner: adam-fowler
- License: apache-2.0
- Created: 2021-05-29T21:27:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-02T06:57:56.000Z (3 months ago)
- Last Synced: 2024-10-16T11:09:33.780Z (28 days ago)
- Topics: jmespath, json, swift
- Language: Swift
- Homepage:
- Size: 83 KB
- Stars: 36
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JMESPath for Swift
Swift implementation of [JMESPath](https://jmespath.org/), a query language for JSON. This package is fully compliant with the [JMESPath Specification](https://jmespath.org/specification.html)
## Usage
Below is a simple example of usage.
```swift
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
```swift
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!")
```