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
Name | Type | Description |
---|---|---|
str | string | JSON string |
Returns
any
Parsed json object
Example
const str = '[123, 12.3, 11223344556677889900]';
const result = parse(str);
// result = [123, 12.3, 11223344556677890048n]
Defined in
parseAlwaysAsBig
▸ parseAlwaysAsBig(str
): any
Convert JSON string to JSON object with all numbers as bigint
Parameters
Name | Type | Description |
---|---|---|
str | string | JSON string |
Returns
any
Parsed json object
Example
const str = '[123, 12.3, 1234567890]';
const result = parseAlwaysAsBig(str);
// result = [123n, 12.3, 1234567890n]
Defined in
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
Name | Type | Description |
---|---|---|
value | unknown | JSON object |
replacer? | any | Function that alters the behavior of the stringification process |
space? | string | number | Used 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]'