# JsonPath
<span class="source-link">[[Source]](src/json/json_path.md#L-0-1)</span>

Compiled JSONPath query for extracting values from JSON documents.

JSONPath queries navigate JSON structures using string path expressions
(RFC 9535). Compile a path with `JsonPathParser.parse()`, then apply
it to any number of documents with `query()`:

```pony
match JsonPathParser.parse("$.store.book[*].author")
| let path: JsonPath =>
  let authors = path.query(doc)
| let err: JsonPathParseError =>
  env.err.print(err.string())
end
```

Evaluation follows RFC 9535 semantics: missing keys, out-of-bounds
indices, and type mismatches produce empty results, never errors.
Only malformed path strings produce errors (at parse time). Filter
expressions support function extensions (`length`, `count`, `match`,
`search`, `value`) per RFC 9535 Section 2.4.

For simple single-value extraction, `query_one()` returns the first
match or JsonNotFound.


```pony
class val JsonPath
```

## Public Functions

### query
<span class="source-link">[[Source]](src/json/json_path.md#L-0-33)</span>


Execute this query against a JSON document.

Returns all matching values. Returns an empty array if no values
match. Evaluation never errors.


```pony
fun box query(
  root: JsonValue)
: Array[JsonValue] val
```
#### Parameters

*   root: [JsonValue](json-JsonValue.md)

#### Returns

* [Array](builtin-Array.md)\[[JsonValue](json-JsonValue.md)\] val

---

### query_one
<span class="source-link">[[Source]](src/json/json_path.md#L-0-42)</span>


Execute this query and return the first matching value, or
JsonNotFound if no values match.

Convenience for paths known to select at most one value.


```pony
fun box query_one(
  root: JsonValue)
: (JsonValue | JsonNotFound val)
```
#### Parameters

*   root: [JsonValue](json-JsonValue.md)

#### Returns

* ([JsonValue](json-JsonValue.md) | [JsonNotFound](json-JsonNotFound.md) val)

---

