From 92969090ed8d4fea7c6cc05e26a0d6e4c3788404 Mon Sep 17 00:00:00 2001 From: Jeffrey Macko Date: Sat, 14 Nov 2026 00:23:21 +0100 Subject: [PATCH 1/2] Add a landing page on GitHub Pages site/index.html presents the library: what JSONPath is, with three queries on the README's bookstore; six features; the two Dialects side by side; a tabbed code tour; who it is for; quality numbers (715/715 compliance cases, 322 Sextant tests, 0 dependencies, 4 CI builds); and the install snippet. One static file, light and dark, no external requests. .github/workflows/pages.yml deploys site/ on pushes to main that touch it, as in swift-arazzo. The code tour and install snippet are copied from the README and marked data-readme; ReadmeTests.sitePageQuotesTheReadme fails when one of their lines is not a README line, so the page cannot drift from the snippets the README tests run. AGENTS.md says to update the page with the README. The README links the site, and its install snippet now names the latest release, 0.0.4, instead of 0.0.1. --- .github/workflows/pages.yml | 41 ++ AGENTS.md | 1 + README.md | 5 +- Tests/JSONPathTests/ReadmeTests.swift | 26 ++ site/index.html | 586 ++++++++++++++++++++++++++ 5 files changed, 658 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pages.yml create mode 100644 site/index.html diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..deef31c --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,41 @@ +name: Pages + +# Publishes site/, the project's landing page, to GitHub Pages when it changes on main. +on: + push: + branches: [main] + paths: [site/**, .github/workflows/pages.yml] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: pages + cancel-in-progress: false + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Configure Pages + uses: actions/configure-pages@v5 + - name: Upload site + uses: actions/upload-pages-artifact@v3 + with: + path: site + - name: Deploy + id: deployment + uses: actions/deploy-pages@v4 diff --git a/AGENTS.md b/AGENTS.md index 9be70af..1ce5129 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,6 +18,7 @@ Read `CONSTRAINTS.md` before writing code. Do not weaken it to make a change pas `README.md` is the user documentation and DocC comments are the API reference (Swift Package Index builds docs for `JSONPath`, see `.spi.yml`). In the same change as any API or behaviour change: - Update the doc comment on every public declaration you touch. - Update every README section, example and table the change affects (`grep -n "" README.md`), including the Dialect feature table. +- `site/index.html` is the landing page (GitHub Pages, `.github/workflows/pages.yml`). Its code tour and install snippet quote the README (`data-readme` blocks, checked by `ReadmeTests.sitePageQuotesTheReadme`); its feature claims, dialect table and numbers repeat the README: update them in the same change. - Keep README snippets compiling: `Tests/JSONPathTests/ReadmeTests.swift` mirrors them, so a changed snippet changes its test. ## Build and test diff --git a/README.md b/README.md index 89b1f63..5dbad01 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmackoj%2Fswift-jsonpath%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/mackoj/swift-jsonpath) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmackoj%2Fswift-jsonpath%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/mackoj/swift-jsonpath) +**[Website](https://mackoj.github.io/swift-jsonpath/)** · +**[API reference](https://swiftpackageindex.com/mackoj/swift-jsonpath/documentation/jsonpath)** + A complete JSONPath implementation in pure Swift — no Foundation, no dependencies — supporting both the IETF standard and the widely deployed Jayway dialect, with JSON Pointer (RFC 6901) alongside it. @@ -31,7 +34,7 @@ the IETF standard and the widely deployed Jayway dialect, with JSON Pointer (RFC ```swift dependencies: [ - .package(url: "https://github.com/mackoj/swift-jsonpath.git", from: "0.0.1"), + .package(url: "https://github.com/mackoj/swift-jsonpath.git", from: "0.0.4"), ], targets: [ .target(name: "MyTool", dependencies: [.product(name: "JSONPath", package: "swift-jsonpath")]), diff --git a/Tests/JSONPathTests/ReadmeTests.swift b/Tests/JSONPathTests/ReadmeTests.swift index 90835d1..73c1df6 100644 --- a/Tests/JSONPathTests/ReadmeTests.swift +++ b/Tests/JSONPathTests/ReadmeTests.swift @@ -1,3 +1,4 @@ +import Foundation import JSONPath import Testing @@ -13,6 +14,31 @@ struct ReadmeTests { ], "bicycle": {"color": "red", "price": 19.95}}} """) + /// The landing page repeats README snippets in its code tour and install section (`data-readme` blocks); every + /// line of them must be a README line, so this suite's checks of the README cover the page too. + @Test func sitePageQuotesTheReadme() throws { + // Given the README and the landing page + let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent() + .deletingLastPathComponent() + let readme = try String(contentsOf: root.appendingPathComponent("README.md"), encoding: .utf8) + let page = try String(contentsOf: root.appendingPathComponent("site/index.html"), encoding: .utf8) + + // When the page's README blocks are read back as text + let blocks = page.components(separatedBy: " data-readme>").dropFirst().map { block in + String(block.prefix { $0 != "<" }) + .replacingOccurrences(of: "<", with: "<").replacingOccurrences(of: ">", with: ">") + .replacingOccurrences(of: """, with: "\"").replacingOccurrences(of: "&", with: "&") + } + let readmeLines = Set(readme.split(separator: "\n", omittingEmptySubsequences: false).map(String.init)) + let strayLines = blocks.flatMap { $0.split(separator: "\n").map(String.init) }.filter { + !readmeLines.contains($0) + } + + // Then there are blocks, and each of their lines is in the README + #expect(blocks.count == 9) + #expect(strayLines == []) + } + @Test func usage() throws { let document = Self.document let cheap = try JSONPath("$.store.book[?@.price < 10].title") diff --git a/site/index.html b/site/index.html new file mode 100644 index 0000000..af7b8f6 --- /dev/null +++ b/site/index.html @@ -0,0 +1,586 @@ + + + + + +swift-jsonpath · JSONPath for Swift + + + + + + + + + + + + +
+ +
+
+
+
    +
  • RFC 9535
  • +
  • Jayway dialect
  • +
  • JSON Pointer
  • +
  • Zero dependencies
  • +
  • Swift 6
  • +
  • MIT
  • +
+

JSONPath for Swift.
Both dialects. No dependencies.

+

Query, point into and rewrite JSON with the IETF standard or with the Jayway syntax your users already know. Pure Swift with no Foundation and no imports, so it runs anywhere Swift runs: iOS apps, macOS tools, Linux servers.

+ +
+
+
Query.swift
+
import JSONPath
+
+let document = try JSONValue(parsing: json)
+
+// RFC 9535: all 715 compliance cases pass
+try JSONPath("$.store.book[?@.price < 10].title")
+    .values(in: document)
+// ["Sayings of the Century", "Moby Dick"]
+
+// The Jayway dialect, path functions included
+try JSONPath("$.store.book.length()", dialect: .jayway)
+    .values(in: document)  // [3]
+
+// Rewrite every match, key order kept
+var copy = document
+try copy.replace(JSONPath("$..price"), with: 0)
+
+
+
+ +
+
+

What is JSONPath

+

XPath for JSON, now an IETF standard.

+

A JSONPath expression selects values from a JSON document, the way a CSS selector picks elements from a page. It started as an informal proposal, spread through Jayway JsonPath in Java, and became RFC 9535 in 2024. On the bookstore document from the README:

+
+
+ RFC 9535 +
$..price
+ selects +
[8.95, 8.99, 22.99, 19.95]
+

Every price, at any depth.

+
+
+ RFC 9535 +
$.store.book[?@.price < 10].title
+ selects +
["Sayings of the Century", "Moby Dick"]
+

A filter on each book, then a member of the ones that pass.

+
+
+ Jayway +
$.store.book.length()
+ selects +
[3]
+

A path function, from the dialect most existing queries are written in.

+
+
+

Each result comes with its location as a normalized path ($['store']['book'][0]['title']) or a JSON Pointer (/store/book/0/title), so you can go back and change it.

+
+
+ +
+
+

Features

+

Everything you need to work with JSON by path.

+

One small package: the query languages, the JSON model they run on, and the tools around them.

+
+
+
+

RFC 9535, to the letter

+

The strict grammar, well-typedness checked when the path is parsed, and the length count match search value functions with I-Regexp. Passes all 715 cases of the official compliance suite.

+
+
+
+

The Jayway dialect, verified

+

[?(…)] filters, loose comparisons, =~ in contains anyof and the other operators, and path functions like .avg(). Passes Sextant's whole test suite. JSONPath(anyDialect:) accepts whichever a user types.

+
+
+
+

Mutations and JSON Pointer

+

Replace, remove or transform every node a path selects. Address one value with an RFC 6901 JSONPointer, convert a query's results into pointers, and set values by pointer, appending with -.

+
+
+
+

An order-preserving JSON model

+

JSONValue keeps object members in document order through parsing, querying, mutation and printing. A strict RFC 8259 parser, a pretty printer, and a Codable bridge that keeps key order too.

+
+
+
+

Built for editors

+

Token ranges for syntax colouring in both dialects, even on an expression that is still being typed. Typed errors with the position of the problem, and JSONPath.validate for a quick yes or no.

+
+
+
+

Zero dependencies, Swift 6

+

No Foundation and no packages: on Linux it links only the standard library and libm. Strict concurrency, and every public type is a Sendable value.

+
+
+
+
+ +
+
+

Two dialects, one API

+

The standard for new queries. Jayway for the ones you already have.

+

Pick the dialect per path. Both return the same JSONValue results and normalized paths, and the differences between them are written down, not discovered in production.

+
+ + + + + + + + + + + + +
Feature.rfc9535.jayway
Names, wildcards, indices, slices, unions, descendants✓✓
Filters[?expr]; on objects, tests the members[?(expr)] / [?expr]; on objects, tests the object itself
Comparisonsstrict and typedloose ('1' == 1), plus === / !==
Functions in filterslength count match search valuesame
Jayway operators–=~ /re/flags, in, nin, contains, size, empty, anyof, …
Path functions–length() avg() sum() min() max() concat() keys() …
Implicit root (store.book)–✓
Relation on a missing pathfalseerror (the filter fails)
+
+

The complete table is in the README.

+
+
+ +
+
+

Code tour

+

Short, typed, and checked by the compiler.

+

These snippets come from the README, which the test suite compiles and runs, so they stay correct.

+
+
+ + + + + + +
+ +
+

Parse a document, then ask a path for values, normalized paths or both. Filters, descendants and the RFC 9535 functions work as the standard says.

+
import JSONPath
+
+let document = try JSONValue(parsing: """
+    {"store": {"book": [
+      {"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95},
+      {"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99},
+      {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "price": 22.99}
+    ], "bicycle": {"color": "red", "price": 19.95}}}
+    """)
+
+let cheap = try JSONPath("$.store.book[?@.price < 10].title")
+try cheap.values(in: document)         // ["Sayings of the Century", "Moby Dick"]
+try cheap.paths(in: document)          // [$['store']['book'][0]['title'], $['store']['book'][1]['title']]
+try cheap.nodes(in: document)          // locations + values
+try document.query("$..price")         // [8.95, 8.99, 22.99, 19.95]
+
+try JSONPath("$.store.book[?match(@.author, '.*Tolkien')].title").values(in: document)
+try JSONPath("$.store.book[?count(@.isbn) > 0].title").values(in: document)
+
+ + + + + + + + + + +
+
+
+ +
+
+

Built for

+

Apps, tools and servers that read JSON they did not design.

+
+
+

Configuration and remote data

+

Pull the values you need out of a large or changing payload with one expression instead of a tower of Codable types, and decode just that part into your model.

+
+
+

API testing and workflows

+

Assert on responses and extract values between steps. swift-arazzo evaluates OpenAPI Arazzo JSONPath criteria with it.

+
+
+

Developer tools and editors

+

A query field that accepts both dialects, validates as you type and colours the expression, with results you can jump to by normalized path or JSON Pointer.

+
+
+

Porting from Java, Android or Sextant

+

Existing Jayway queries keep their meaning: loose comparisons, operators and path functions behave as Jayway's, checked against Sextant's own tests.

+
+
+
+
+ +
+
+

Quality

+

Checked against the standard and against Jayway.

+
+
715 / 715cases of the official JSONPath Compliance Test Suite passed, in RFC 9535 mode
+
322tests from Sextant's suite, ported to Swift Testing, pin the Jayway dialect
+
0dependencies and 0 imports: not even Foundation
+
4CI builds on every change: Linux on Swift 6.0, 6.1 and 6.2, and macOS, plus API-breakage and DocC checks
+
+

A differential run against Sextant agrees on every input except where Sextant itself is buggy; those differences are commented in the tests.

+
+
+ +
+
+

Install

+

Add it to your package.

+
+
+
Package.swift
+
dependencies: [
+    .package(url: "https://github.com/mackoj/swift-jsonpath.git", from: "0.0.4"),
+],
+targets: [
+    .target(name: "MyTool", dependencies: [.product(name: "JSONPath", package: "swift-jsonpath")]),
+]
+
+
+
    +
  • Swift 6.0+ on Linux, macOS 13+, iOS 16+, tvOS 16+, watchOS 9+ and visionOS 1+.
  • +
  • One product, JSONPath: both dialects, JSONValue, JSON Pointer, mutations and the Codable bridge.
  • +
  • API reference on the Swift Package Index; guide and examples in the README.
  • +
+ +
+
+
+
+ +
+ + + + + + From 1663f42fd416f9973f2da0f156d85457b5e90349 Mon Sep 17 00:00:00 2001 From: Jeffrey Macko Date: Sat, 14 Nov 2026 00:26:10 +0100 Subject: [PATCH 2/2] Landing page: benchmark table, 0.0.4 against main Six benchmarks from Benchmarks/ (#8) on the generated 1.4 MB document: parsing, the 8 RFC 9535 and Jayway queries, a descendant scan, and replace and remove. The numbers are #8's p50s, so this lands after it. --- site/index.html | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/site/index.html b/site/index.html index af7b8f6..3627727 100644 --- a/site/index.html +++ b/site/index.html @@ -475,8 +475,8 @@

Porting from Java, Android or Sextant

-

Quality

-

Checked against the standard and against Jayway.

+

Quality and speed

+

Checked against the standard and against Jayway. Measured on every change.

715 / 715cases of the official JSONPath Compliance Test Suite passed, in RFC 9535 mode
322tests from Sextant's suite, ported to Swift Testing, pin the Jayway dialect
@@ -484,6 +484,20 @@

Checked against the standard and against Jayway.

4CI builds on every change: Linux on Swift 6.0, 6.1 and 6.2, and macOS, plus API-breakage and DocC checks

A differential run against Sextant agrees on every input except where Sextant itself is buggy; those differences are commented in the tests.

+
+ + + + + + + + + + +
Benchmark on a 1.4 MB document (p50, Apple silicon)0.0.4main
Parse the JSON text26.4 ms7.9 ms
Run 8 RFC 9535 queries, from $.store.book[0].title to $..*117 ms15.3 ms
Run the same 8 queries in the Jayway dialect66.7 ms9.3 ms
Find every author with $..author9.9 ms1.3 ms
Replace all 5,000 prices with $..price419 ms10.0 ms
Remove the books a filter selects111 ms2.4 ms
+
+

Benchmarks use package-benchmark and live in the repository: swift package --package-path Benchmarks benchmark.