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

A non-finite `F64` — infinity or NaN — has no JSON representation (RFC 8259
numbers are finite), so it serializes as `null`.


```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-32)</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-38)</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-32)</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-32)</span>


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

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

#### Returns

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

---

