Skip to main content
Version: Next

Namespace: json

Functions​

parse​

â–¸ parse(str): any

Convert JSON string to JSON object

NOTE: the String() wrapping is used so the behavior conforms to JSON.parse() which can accept simple data types but is not represented in the default typing

Parameters​

NameTypeDescription
strstringJSON string

Returns​

any

Parsed json object

Example

const str = '[123, 12.3, 11223344556677889900]';
const result = parse(str);
// result = [123, 12.3, 11223344556677890048n]

Defined in​

src/utils/json.ts:27


parseAlwaysAsBig​

â–¸ parseAlwaysAsBig(str): any

Convert JSON string to JSON object with all numbers as bigint

Parameters​

NameTypeDescription
strstringJSON string

Returns​

any

Parsed json object

Example

const str = '[123, 12.3, 1234567890]';
const result = parseAlwaysAsBig(str);
// result = [123n, 12.3, 1234567890n]

Defined in​

src/utils/json.ts:41


stringify​

â–¸ stringify(value, replacer?, space?, numberStringifiers?): string

Convert JSON object to JSON string

NOTE: the not-null assertion is used so the return type conforms to JSON.stringify() which can also return undefined but is not represented in the default typing

Parameters​

NameTypeDescription
valueunknownJSON object
replacer?anyFunction that alters the behavior of the stringification process
space?string | numberUsed to insert white space into the output JSON string
numberStringifiers?NumberStringifier[]Function used to stringify numbers (returning undefined will delete the property from the object)

Returns​

string

JSON string

Example

const value = [123, 12.3, 1234567890];
const result = stringify(value);
// result = '[123,12.3,1234567890]'

Defined in​

src/utils/json.ts:62


stringifyAlwaysAsBig​

â–¸ stringifyAlwaysAsBig(value, replacer?, space?, numberStringifiers?): string

Parameters​

NameType
valueunknown
replacer?any
space?string | number
numberStringifiers?NumberStringifier[]

Returns​

string

Deprecated

equivalent to 'stringify', alias will be removed

Defined in​

src/utils/json.ts:62