JsonPathTemplate

An RFC 9535 JSONPath query with named placeholders, compiled once and bound to values any number of times (SPEC.md §10.6). A placeholder ${name} stands where the RFC allows a literal: an operand of a comparison, or a value argument of a function such as the pattern of match.

val byCustomer = JsonPathTemplate.compile("\$.orders[?@.customer == \${customer} && @.total >= \${min}]")
val path = byCustomer.bind("customer" to JsonQueryValue.Str(name), "min" to JsonQueryValue.Num(100))

bind puts each value into the compiled query as a literal, never as text, so no value can change what the query asks: x' || true || 'x is one string the query compares with. The bound JsonPath is the one JsonPath.compile makes of the template's text with each placeholder replaced by its value's literal, and that text is its JsonPath.toString; binding doesn't parse it again.

Placeholders are an extension of RFC 9535, which has none, and JsonPath.compile refuses them. Immutable and thread-safe; two templates are equal when their texts are.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The names of the placeholders, each once, in the order they first appear in the text.

Functions

Link copied to clipboard

The query with each placeholder replaced by the literal of its value in values, which has a value for every one of parameters and for nothing else; a JsonQueryValue.Json value has no literal form. Each of these is an IllegalArgumentException. A value that makes the query invalid, such as a string with an unpaired surrogate, a number whose exponent is out of range or a string that takes the query beyond its length limit, throws InvalidJsonPathException naming the offset in the bound text, as compiling that text would.

fun bind(vararg values: Pair<String, JsonQueryValue>): JsonPath

bind with the values given as pairs: bind("id" to JsonQueryValue.Str(id)).

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String