Skip to content

JsonNav

[Source]

Chained navigation wrapper for JSON values. Wraps a JsonValue and provides safe chained access where JsonNotFound propagates through the chain — no exceptions until you extract a typed terminal value.

let nav = JsonNav(json)
try
  let name = nav("user")("name").as_string()?
  let age = nav("user")("age").as_i64()?
end

class val JsonNav

Constructors

create

[Source]

Wrap a JSON value for navigation.

new val create(
  value: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val))
: JsonNav val^

Parameters

Returns


Public Functions

apply

[Source]

Navigate into an object by key or array by index. If the current value is JsonNotFound, the wrong type, or the key/index is missing, returns a JsonNotFound-wrapping nav. JsonNotFound propagates through subsequent navigations.

fun box apply(
  key_or_index: (String val | USize val))
: JsonNav val

Parameters

Returns


as_string

[Source]

Extract as String. Raises if not a string or JsonNotFound.

fun box as_string()
: String val ?

Returns


as_i64

[Source]

Extract as I64. Raises if not an integer or JsonNotFound.

fun box as_i64()
: I64 val ?

Returns


as_f64

[Source]

Extract as F64. Raises if not a float or JsonNotFound.

fun box as_f64()
: F64 val ?

Returns


as_bool

[Source]

Extract as Bool. Raises if not a boolean or JsonNotFound.

fun box as_bool()
: Bool val ?

Returns


as_null

[Source]

Extract as None (JSON null). Raises if not null or JsonNotFound.

fun box as_null()
: None val ?

Returns


as_object

[Source]

Extract as JsonObject. Raises if not an object or JsonNotFound.

fun box as_object()
: JsonObject val ?

Returns


as_array

[Source]

Extract as JsonArray. Raises if not an array or JsonNotFound.

fun box as_array()
: JsonArray val ?

Returns


json

[Source]

Get the raw value for pattern matching.

fun box json()
: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val | JsonNotFound val)

Returns


found

[Source]

Check whether navigation succeeded (value is not JsonNotFound).

fun box found()
: Bool val

Returns


size

[Source]

Size of the wrapped collection. Raises if not an object or array.

fun box size()
: USize val ?

Returns