Skip to content

Json Serializer

Spice
import "std/text/json-serializer";

JsonSerializer struct

Serializer for JSON output.

In compact mode (the default) the output contains no insignificant whitespace. In pretty mode nested arrays and objects are laid out with two-space indentation. Either way the result round-trips through parseJson from "std/text/json-parser".

Constructors

ctor

Spice
public p JsonSerializer.ctor(bool pretty = false)

Construct a JSON serializer

Parameters

Name Type Description
pretty bool Emit human-readable output with two-space indentation (default: false)

Methods

serialize

Spice
public f<String> JsonSerializer.serialize(JsonValue& value)

Serializes a JSON value into a JSON string

Parameters

Name Type Description
value JsonValue& JSON value to serialize

Returns: String — JSON representation

serialize

Spice
public f<String> JsonSerializer.serialize(JsonValue* value)

Serializes a JSON value into a JSON string

Parameters

Name Type Description
value JsonValue* JSON value to serialize

Returns: String — JSON representation