Module: json

Table of contents

Classes

Interfaces

Type Aliases

Functions

Type Aliases

JsonValue

Ƭ JsonValue: null | number | boolean | string | JsonObject | JsonValue[]

A JSON value

Defined in

src/json.d.ts:20

Functions

fromJson

fromJson(value, options?): Node

Encode the given JSON value into a JiK node

Parameters

NameTypeDescription
valueJsonValueThe JSON value to encode
options?FromJsonOptions-

Returns

Node

Throws

If the given value contains cycles.

Defined in

src/json.d.ts:208


parse

parse(text, reviver?): JsonValue

Parse the given JiK text to its encoded JSON value

Parameters

NameTypeDescription
textstringThe JiK text to parse
reviver?JiKReviver<JsonValue>-

Returns

JsonValue

Throws

If the given text is not a valid JiK document

Defined in

src/json.d.ts:236

parse(text, reviver): unknown

Parse the given JiK text to its encoded JSON value

Parameters

NameTypeDescription
textstringThe JiK text to parse
reviverJiKReviver<unknown>-

Returns

unknown

Throws

If the given text is not a valid JiK document

Defined in

src/json.d.ts:243


stringify

stringify(value, options?): string

Stringify the given JSON value into JiK text

Parameters

NameTypeDescription
valueunknownThe JSON value to encode
options?StringifyOptionsOptional options

Returns

string

Throws

If the given JSON value contains cycles.

Defined in

src/json.d.ts:305

stringify(value, replacer?, indentation?): string

Stringify the given JSON value into JiK text

This function's signrature is explicitly kept similar to JSON.stringify.

Parameters

NameTypeDescription
valueunknownThe JSON value to encode
replacer?(key: string | number, value: unknown, originalValue: unknown) => unknown-
indentation?string | numberThe indentation to give each nested level of node, either the actual indentation string or the number of spaces

Returns

string

Throws

If the given JSON value contains cycles.

Defined in

src/json.d.ts:315


toJson

toJson(nodeOrDocument, options): JsonObject

Extract the JSON value encoded into the given JiK node or document.

If passed a document, the document must contain a single node, which acts as the root of the JiK value.

Parameters

NameTypeDescription
nodeOrDocumentNode | DocumentA valid JiK node or a document containing a single node which is a valid JiK node
optionsToJsonOptions & ToJsonType<"object"> & { reviver?: undefined }-

Returns

JsonObject

See

https://github.com/kdl-org/kdl/blob/76d5dd542a9043257bc65476c0a70b94667052a7/JSON-IN-KDL.md

Throws

If the given node is not a valid JiK node or if the given document doesn't contain exactly one node

Defined in

src/json.d.ts:101

toJson(nodeOrDocument, options): JsonValue[]

Extract the JSON value encoded into the given JiK node or document.

If passed a document, the document must contain a single node, which acts as the root of the JiK value.

Parameters

NameTypeDescription
nodeOrDocumentNode | DocumentA valid JiK node or a document containing a single node which is a valid JiK node
optionsToJsonOptions & ToJsonType<"array"> & { reviver?: undefined }-

Returns

JsonValue[]

See

https://github.com/kdl-org/kdl/blob/76d5dd542a9043257bc65476c0a70b94667052a7/JSON-IN-KDL.md

Throws

If the given node is not a valid JiK node or if the given document doesn't contain exactly one node

Defined in

src/json.d.ts:114

toJson(nodeOrDocument, options?): JsonValue

Extract the JSON value encoded into the given JiK node or document.

If passed a document, the document must contain a single node, which acts as the root of the JiK value.

Parameters

NameTypeDescription
nodeOrDocumentNode | DocumentA valid JiK node or a document containing a single node which is a valid JiK node
options?ToJsonOptions & Partial<ToJsonType<string>> & Partial<ToJsonReviver<JsonValue>>-

Returns

JsonValue

See

https://github.com/kdl-org/kdl/blob/76d5dd542a9043257bc65476c0a70b94667052a7/JSON-IN-KDL.md

Throws

If the given node is not a valid JiK node or if the given document doesn't contain exactly one node

Defined in

src/json.d.ts:127

toJson(nodeOrDocument, options?): unknown

Extract the JSON value encoded into the given JiK node or document.

If passed a document, the document must contain a single node, which acts as the root of the JiK value.

Parameters

NameTypeDescription
nodeOrDocumentNode | DocumentA valid JiK node or a document containing a single node which is a valid JiK node
options?ToJsonOptions & Partial<ToJsonType<string>> & Partial<ToJsonReviver<unknown>>-

Returns

unknown

See

https://github.com/kdl-org/kdl/blob/76d5dd542a9043257bc65476c0a70b94667052a7/JSON-IN-KDL.md

Throws

If the given node is not a valid JiK node or if the given document doesn't contain exactly one node

Defined in

src/json.d.ts:142