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