# JsonNav
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-1)</span>

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.

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


```pony
class val JsonNav
```

## Constructors

### create
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-19)</span>


Wrap a JSON value for navigation.

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

*   value: ([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

* [JsonNav](json-JsonNav.md) val^

---

## Public Functions

### apply
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-27)</span>


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.


```pony
fun box apply(
  key_or_index: (String val | USize val))
: JsonNav val
```
#### Parameters

*   key_or_index: ([String](builtin-String.md) val | [USize](builtin-USize.md) val)

#### Returns

* [JsonNav](json-JsonNav.md) val

---

### as_string
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-50)</span>


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

```pony
fun box as_string()
: String val ?
```

#### Returns

* [String](builtin-String.md) val ?

---

### as_i64
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-54)</span>


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

```pony
fun box as_i64()
: I64 val ?
```

#### Returns

* [I64](builtin-I64.md) val ?

---

### as_f64
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-58)</span>


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

```pony
fun box as_f64()
: F64 val ?
```

#### Returns

* [F64](builtin-F64.md) val ?

---

### as_bool
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-62)</span>


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

```pony
fun box as_bool()
: Bool val ?
```

#### Returns

* [Bool](builtin-Bool.md) val ?

---

### as_null
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-66)</span>


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

```pony
fun box as_null()
: None val ?
```

#### Returns

* [None](builtin-None.md) val ?

---

### as_object
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-70)</span>


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

```pony
fun box as_object()
: JsonObject val ?
```

#### Returns

* [JsonObject](json-JsonObject.md) val ?

---

### as_array
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-74)</span>


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

```pony
fun box as_array()
: JsonArray val ?
```

#### Returns

* [JsonArray](json-JsonArray.md) val ?

---

### json
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-80)</span>


Get the raw value for pattern matching.

```pony
fun box json()
: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val | JsonNotFound 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)

---

### found
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-84)</span>


Check whether navigation succeeded (value is not JsonNotFound).

```pony
fun box found()
: Bool val
```

#### Returns

* [Bool](builtin-Bool.md) val

---

### size
<span class="source-link">[[Source]](src/json/json_nav.md#L-0-88)</span>


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

```pony
fun box size()
: USize val ?
```

#### Returns

* [USize](builtin-USize.md) val ?

---

