noggin

serializers/json

JSON <-> NogginDocument conversion. The YAML form is what noggins live in on disk; the JSON form is what the CLI's --json mode and RPC payloads use for the document body of an envelope.

toJson()

function toJson(doc: NogginDocument, opts?: {
  pretty?: boolean;
}): string;

Serialize a NogginDocument to JSON. With pretty: true (the default) the output is indented with two spaces and ends in a trailing newline so diffs and content hashes are deterministic.

Parameters

ParameterType
docNogginDocument
opts?{ pretty?: boolean; }
opts.pretty?boolean

Returns

string

fromJson()

function fromJson(text: string): NogginDocument;

Parse a JSON noggin document. Throws NogginError with code 'invalid-document' for structural failures or 'unsupported-schema' when the document declares a schema version this build doesn't speak.

Empty/whitespace input is treated as a fresh empty document.

Parameters

ParameterType
textstring

Returns

NogginDocument