Skip to content

JsonPath

[Source]

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():

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.

class val JsonPath

Public Functions

query

[Source]

Execute this query against a JSON document. Returns all matching values. Returns an empty array if no values match. Evaluation never errors.

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

Returns


query_one

[Source]

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.

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

Returns