# 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
```

## Constructors

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


```pony
new val create(
  data': Vec[JSONValue] val = pc.Vec[JSONValue)
: JSONArray val^
```
#### Parameters

*   data': [Vec](collections-persistent-Vec.md)\[[JSONValue](json-JSONValue.md)\] val = pc.Vec[JSONValue

#### 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)
: JSONValue ?
```
#### Parameters

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

#### Returns

* [JSONValue](json-JSONValue.md) ?

---

### size
<span class="source-link">[[Source]](src/json/json_array.md#L-0-29)</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-35)</span>


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


```pony
fun box update(
  i: USize val,
  value: JSONValue)
: JSONArray val ?
```
#### Parameters

*   i: [USize](builtin-USize.md) val
*   value: [JSONValue](json-JSONValue.md)

#### Returns

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

---

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


Return a new array with value appended.


```pony
fun box push(
  value: JSONValue)
: JSONArray val
```
#### Parameters

*   value: [JSONValue](json-JSONValue.md)

#### Returns

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

---

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


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


```pony
fun box pop()
: (JSONArray val , JSONValue) ?
```

#### Returns

* ([JSONArray](json-JSONArray.md) val , [JSONValue](json-JSONValue.md)) ?

---

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


Iterate over values.


```pony
fun box values()
: VecValues[JSONValue] ref
```

#### Returns

* [VecValues](collections-persistent-VecValues.md)\[[JSONValue](json-JSONValue.md)\] ref

---

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


Iterate over (index, value) pairs.


```pony
fun box pairs()
: VecPairs[JSONValue] ref
```

#### Returns

* [VecPairs](collections-persistent-VecPairs.md)\[[JSONValue](json-JSONValue.md)\] ref

---

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


Compact JSON serialization.


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

#### Returns

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

---

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


Pretty-printed JSON serialization.


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

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

#### Returns

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

---

