JSONNav¶
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
Constructors¶
create¶
Wrap a JSON value for navigation.
Parameters¶
- value: JSONValue
Returns¶
- JSONNav val^
Public Functions¶
apply¶
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.
Parameters¶
Returns¶
- JSONNav val
as_string¶
Extract as String. Raises if not a string or JSONNotFound.
Returns¶
- String val ?
as_i64¶
Extract as I64. Raises if not an integer or JSONNotFound.
Returns¶
- I64 val ?
as_f64¶
Extract as F64. Raises if not a float or JSONNotFound.
Returns¶
- F64 val ?
as_bool¶
Extract as Bool. Raises if not a boolean or JSONNotFound.
Returns¶
- Bool val ?
as_null¶
Extract as None (JSON null). Raises if not null or JSONNotFound.
Returns¶
- None val ?
as_object¶
Extract as JSONObject. Raises if not an object or JSONNotFound.
Returns¶
- JSONObject val ?
as_array¶
Extract as JSONArray. Raises if not an array or JSONNotFound.
Returns¶
- JSONArray val ?
json¶
Get the raw value for pattern matching.
Returns¶
- (JSONValue | JSONNotFound val)
found¶
Check whether navigation succeeded (value is not JSONNotFound).
Returns¶
- Bool val
size¶
Size of the wrapped collection. Raises if not an object or array.
Returns¶
- USize val ?