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

Immutable JSON array backed by a persistent vector.

Construction is via chained `.push()` calls, each returning a new array
with structural sharing:

```pony
let arr = JsonArray
  .push(I64(1))
  .push(I64(2))
  .push(I64(3))
```


```pony
class val JsonArray is
  Stringable box
```

#### Implements

* [Stringable](builtin-Stringable.md) box

---

## Constructors

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


```pony
new val create(
  data': Vec[(JsonObject val | JsonArray val | String val | I64 val | F64 val | Bool val | None val)] val = qualify)
: JsonArray val^
```
#### Parameters

*   data': [Vec](collections-persistent-Vec.md)\[([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)\] val = qualify

#### Returns

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

---

## Public Functions

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


Look up a value by index. Raises if out of bounds.

```pony
fun box apply(
  i: USize val)
: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val) ?
```
#### Parameters

*   i: [USize](builtin-USize.md) 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) ?

---

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


Number of elements.

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

#### Returns

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

---

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


Return a new array with element at index i replaced.
Raises if out of bounds.


```pony
fun box update(
  i: USize val,
  value: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val))
: JsonArray val ?
```
#### Parameters

*   i: [USize](builtin-USize.md) val
*   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

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

---

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


Return a new array with value appended.

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

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

---

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


Return (new array without last element, removed element).
Raises if empty.


```pony
fun box pop()
: (JsonArray val , (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val)) ?
```

#### Returns

* ([JsonArray](json-JsonArray.md) val , ([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)) ?

---

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


Iterate over values.

```pony
fun box values()
: VecValues[(JsonObject val | JsonArray val | String val | I64 val | F64 val | Bool val | None val)] ref
```

#### Returns

* [VecValues](collections-persistent-VecValues.md)\[([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)\] ref

---

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


Iterate over (index, value) pairs.

```pony
fun box pairs()
: VecPairs[(JsonObject val | JsonArray val | String val | I64 val | F64 val | Bool val | None val)] ref
```

#### Returns

* [VecPairs](collections-persistent-VecPairs.md)\[([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)\] ref

---

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


Compact JSON serialization.

```pony
fun box string()
: String iso^
```

#### Returns

* [String](builtin-String.md) iso^

---

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


Pretty-printed JSON serialization.

```pony
fun box pretty_string(
  indent: String val = "  ")
: String iso^
```
#### Parameters

*   indent: [String](builtin-String.md) val = "  "

#### Returns

* [String](builtin-String.md) iso^

---

