Skip to content

JSONPrinter

[Source]

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:

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):

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.

primitive val JSONPrinter

Constructors

create

[Source]

new val create()
: JSONPrinter val^

Returns


Public Functions

print

[Source]

Compact JSON serialization of any JSONValue.

fun box print(
  value: JSONValue)
: String iso^

Parameters

Returns


pretty

[Source]

Pretty-printed JSON serialization of any JSONValue.

fun box pretty(
  value: JSONValue,
  indent: String val = "  ")
: String iso^

Parameters

Returns


eq

[Source]

fun box eq(
  that: JSONPrinter val)
: Bool val

Parameters

Returns


ne

[Source]

fun box ne(
  that: JSONPrinter val)
: Bool val

Parameters

Returns