# 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: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val))
: Array[(JsonObject val | JsonArray val | String val | I64 val | F64 val | Bool val | None val)] val
```
#### Parameters

*   root: ([JsonObject](json-JsonObject.md) val | [JsonArray](json-JsonArray.md) val | [String](builtin-String.md) val | 
    [I64](builtin-I64.md) val | [F64](builtin-F64.md) val | [Bool](builtin-Bool.md) val | 
    [None](builtin-None.md) val)

#### Returns

* [Array](builtin-Array.md)\[([JsonObject](json-JsonObject.md) val | [JsonArray](json-JsonArray.md) val | [String](builtin-String.md) val | [I64](builtin-I64.md) val | [F64](builtin-F64.md) val | [Bool](builtin-Bool.md) val | [None](builtin-None.md) val)\] 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: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val))
: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val | JsonNotFound val)
```
#### Parameters

*   root: ([JsonObject](json-JsonObject.md) val | [JsonArray](json-JsonArray.md) val | [String](builtin-String.md) val | 
    [I64](builtin-I64.md) val | [F64](builtin-F64.md) val | [Bool](builtin-Bool.md) val | 
    [None](builtin-None.md) val)

#### Returns

* ([JsonObject](json-JsonObject.md) val | [JsonArray](json-JsonArray.md) val | [String](builtin-String.md) val | 
    [I64](builtin-I64.md) val | [F64](builtin-F64.md) val | [Bool](builtin-Bool.md) val | 
    [None](builtin-None.md) val | [JsonNotFound](json-JsonNotFound.md) val)

---

