A safe method to JSON.stringify a value, useful for debugging and logging purposes.
JSON.stringify
Without modifications, JSON.stringify has several shortcomings in debugging and logging usage:
bigint
Uint8Array
functions
symbols
This method is more helpful in these cases:
0n
<bigint: 0n>
Uint8Array.of(0,0)
<Uint8Array: 0x0000>
function
(x) => x * 2
<function: (x) => x * 2>
symbol
Symbol(A)
<symbol: Symbol(A)>
the data to stringify
the number of spaces to use in
Generated using TypeDoc
A safe method to
JSON.stringify
a value, useful for debugging and logging purposes.Remarks
Without modifications,
JSON.stringify
has several shortcomings in debugging and logging usage:bigint
Uint8Array
s are often encoded in base 10 with newlines between each index itemfunctions
andsymbols
are not clearly markedThis method is more helpful in these cases:
bigint
:0n
→<bigint: 0n>
Uint8Array
:Uint8Array.of(0,0)
→<Uint8Array: 0x0000>
function
:(x) => x * 2
→<function: (x) => x * 2>
symbol
:Symbol(A)
→<symbol: Symbol(A)>