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

Immutable JSON object backed by a persistent hash map.

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

```pony
let obj = JsonObject
  .update("name", "Alice")
  .update("age", I64(30))
```


```pony
class val JsonObject is
  Stringable box
```

#### Implements

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

---

## Constructors

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


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

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

#### Returns

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

---

## Public Functions

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


Look up a value by key. Raises if key is not present.

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

*   key: [String](builtin-String.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) ?

---

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


Look up a value by key, returning default if absent.

```pony
fun box get_or_else(
  key: String val,
  default: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val))
: (JsonObject val | JsonArray val | String val | 
    I64 val | F64 val | Bool val | 
    None val)
```
#### Parameters

*   key: [String](builtin-String.md) val
*   default: ([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

* ([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)

---

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


Check whether a key is present.

```pony
fun box contains(
  key: String val)
: Bool val
```
#### Parameters

*   key: [String](builtin-String.md) val

#### Returns

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

---

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


Number of key-value pairs.

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

#### Returns

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

---

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


Return a new object with the key set to value.

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

*   key: [String](builtin-String.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

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

---

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


Return a new object without the given key. No-op if key is absent.

```pony
fun box remove(
  key: String val)
: JsonObject val
```
#### Parameters

*   key: [String](builtin-String.md) val

#### Returns

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

---

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


Iterate over keys.

```pony
fun box keys()
: MapKeys[String val, (JsonObject val | JsonArray val | String val | I64 val | F64 val | Bool val | None val), HashEq[String val] val] ref
```

#### Returns

* [MapKeys](collections-persistent-MapKeys.md)\[[String](builtin-String.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), [HashEq](collections-HashEq.md)\[[String](builtin-String.md) val\] val\] ref

---

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


Iterate over values.

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

#### Returns

* [MapValues](collections-persistent-MapValues.md)\[[String](builtin-String.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), [HashEq](collections-HashEq.md)\[[String](builtin-String.md) val\] val\] ref

---

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


Iterate over (key, value) pairs.

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

#### Returns

* [MapPairs](collections-persistent-MapPairs.md)\[[String](builtin-String.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), [HashEq](collections-HashEq.md)\[[String](builtin-String.md) val\] val\] ref

---

### string
<span class="source-link">[[Source]](src/json/json_object.md#L-0-61)</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_object.md#L-0-65)</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^

---

