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

Serialize any `JsonValue` to a JSON string. This is the dual of `JsonParser`:
where `JsonParser.parse` turns a `String` into a `JsonValue`, `JsonPrinter`
turns a `JsonValue` back into a JSON `String`.

To serialize Pony data as JSON, build a `JsonValue` and pass it to `print`:

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

env.out.print(JsonPrinter.print(doc))
// {"name":"Alice","age":30}
```

`print` produces compact output; `pretty` produces indented output. Both
accept any `JsonValue`, including scalars (`String`, `I64`, `F64`, `Bool`)
and JSON null (`None`):

```pony
JsonPrinter.print(None)   // null
JsonPrinter.print(true)   // true
JsonPrinter.print("hi")   // "hi"
```


```pony
primitive val JsonPrinter
```

## Constructors

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


```pony
new val create()
: JsonPrinter val^
```

#### Returns

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

---

## Public Functions

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


Compact JSON serialization of any `JsonValue`.

```pony
fun box print(
  value: JsonValue)
: String iso^
```
#### Parameters

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

#### Returns

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

---

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


Pretty-printed JSON serialization of any `JsonValue`.

```pony
fun box pretty(
  value: JsonValue,
  indent: String val = "  ")
: String iso^
```
#### Parameters

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

#### Returns

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

---

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


```pony
fun box eq(
  that: JsonPrinter val)
: Bool val
```
#### Parameters

*   that: [JsonPrinter](json-JsonPrinter.md) val

#### Returns

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

---

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


```pony
fun box ne(
  that: JsonPrinter val)
: Bool val
```
#### Parameters

*   that: [JsonPrinter](json-JsonPrinter.md) val

#### Returns

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

---

