Interface: FromJsonOptions

json.FromJsonOptions

Options for the fromJson function

Hierarchy

Table of contents

Properties

Properties

allowEntries

Optional allowEntries: boolean

Whether to allow literal children to be encoded into values or properties

Defaults to true. This value can be defined specifically for arrays, objects, or the root node.

Defined in

src/json.d.ts:166


allowEntriesInArrays

Optional allowEntriesInArrays: boolean

Whether to allow literal items in the array to be encoded as values on a node

If set to false, all array items will be encoded as children.

If set to true, all leading literal values of arrays will be encoded as node values instead.

The default value is the value of allowEntries, which in turn defaults to true.

Defined in

src/json.d.ts:177


allowEntriesInObjects

Optional allowEntriesInObjects: boolean

Whether to allow literal properties in the object to be encoded as property on a node

If set to false, all node properties will be encoded as children.

If set to true, all properties with literal values of objects will be encoded as node properties instead. Note that this changes the order of properties, which are assumed not to matter in JSON.

The default value is the value of allowEntries, which in turn defaults to true.

Defined in

src/json.d.ts:189


allowEntriesInRoot

Optional allowEntriesInRoot: boolean

Whether to allow literal children to be encoded as values or properties on the root node

This property only has effect if the given value is an object or an array. Literal values are always encoded as values on the root node.

The default value of this option is the value of allowEntriesInArrays or allowEntriesInObjects, depending on the type of the value.

Defined in

src/json.d.ts:199


indentation

Optional indentation: string | number

The indentation to give each nested level of node

If a string is passed, that string is used as indentation. If a number higher than zero is passed, the indentation is set to the whitespace character repeated for that number of times. If zero is passed or no indentation is given, no newlines with indentation will be inserted into the output.

Inherited from

StringifyOptions.indentation

Defined in

src/json.d.ts:256


nodeName

Optional nodeName: string

Name of the root node to create

If no name is passed, the node will be called "-".

Defined in

src/json.d.ts:158


replaceJsonValue

Optional replaceJsonValue: (key: string | number, value: unknown, originalValue: unknown) => unknown

Replacer function called for every JSON value in the data being transformed

The replacer can return any JSON value, which will be used instead of the original value. If undefined is returned, the value will be discarded.

If the originalValue had a toJSON method, it will be called and the result will be the value parameter. In all other cases value and originalValue will be the same value.

Param

The name of the property or the index inside an array

Param

The value being handled

Param

The original value

Type declaration

▸ (key, value, originalValue): unknown

Replacer function called for every JSON value in the data being transformed

The replacer can return any JSON value, which will be used instead of the original value. If undefined is returned, the value will be discarded.

If the originalValue had a toJSON method, it will be called and the result will be the value parameter. In all other cases value and originalValue will be the same value.

Parameters
NameTypeDescription
keystring | numberThe name of the property or the index inside an array
valueunknownThe value being handled
originalValueunknownThe original value
Returns

unknown

Inherited from

StringifyOptions.replaceJsonValue

Defined in

src/json.d.ts:272


replaceKdlValue

Optional replaceKdlValue: (key: string | number, value: Entry | Node, jsonValue: unknown, originalJsonValue: unknown) => undefined | Entry | Node

Replacer function called for every KDL node or entry created

The replacer can return an entry or node. If an entry is returned but an entry would not be valid in the given location, it will be transformed into a node. If undefined is returned, the value will be discarded.

Param

The name of the property or the index inside an array

Param

The entry or node that was created

Param

The JSON value that was transformed into the KDL value

Param

Type declaration

▸ (key, value, jsonValue, originalJsonValue): undefined | Entry | Node

Replacer function called for every KDL node or entry created

The replacer can return an entry or node. If an entry is returned but an entry would not be valid in the given location, it will be transformed into a node. If undefined is returned, the value will be discarded.

Parameters
NameTypeDescription
keystring | numberThe name of the property or the index inside an array
valueEntry | NodeThe entry or node that was created
jsonValueunknownThe JSON value that was transformed into the KDL value
originalJsonValueunknown
Returns

undefined | Entry | Node

Inherited from

StringifyOptions.replaceKdlValue

Defined in

src/json.d.ts:290