flix

0.73.0

Util.Json.JsonPath

enum JsonPath with EqSource
case JsonPath(List[JsonStep])

A path locating a value inside a Json document, as a sequence of JsonSteps.

The List[JsonStep] is stored head-at-root: the first element is the outermost step and the last element is the leaf. Walking head-to-tail yields the natural root-to-leaf order used by toJsonPointer.

Instances

instance Eq[JsonPath]Source
instance Formattable[JsonPath]Source
instance ToString[JsonPath]Source

Definitions

def cons(s: JsonStep, p: JsonPath): JsonPath Source

Prepends s to p. O(1).

This is the decode-side primitive: as a decode error bubbles up, each outer wrapper conses its own step, leaving the head as the outermost (root) step.

def empty(): JsonPath Source

Returns the empty path (the root).

def fromJsonPointer(s: String): Option[JsonPath] Source

Parses a JSON Pointer (RFC 6901) into a JsonPath.

Returns None if s is non-empty and does not start with /, or if a reference token contains an invalid ~ escape.

All-digit segments without leading zeros (or the lone segment "0") classify as Index; everything else classifies as Key. This is a heuristic — round-tripping a Key("123") through toJsonPointer then fromJsonPointer yields Index(123).

def fromList(xs: List[JsonStep]): JsonPath Source

Returns a path with the given steps in root-to-leaf order.

def navigate(p: JsonPath, j: Json): Option[Json] Source

Returns the value at p in j, or None if any step is missing or the shape is wrong (e.g. a Key step into a non-object).

def snoc(p: JsonPath, s: JsonStep): JsonPath Source

Appends s to p. O(n).

This is the navigation-side primitive: when constructing a path forward from the root, each new step extends the leaf end.

def steps(p: JsonPath): List[JsonStep] Source

Returns the steps of p in root-to-leaf order.

def toJsonPointer(p: JsonPath): String Source

Renders p as a JSON Pointer (RFC 6901).

The empty path is rendered as the empty string. A non-empty path is rendered as /-separated reference tokens, where keys are escaped per RFC 6901 (~ -> ~0, / -> ~1) and indices are rendered in decimal.