jsonToString
jsonToString(
value):string
Defined in: core/src/utils/helper.ts:488
Writes a value as indented JSON text, to show or log what a canister call
returned. JSON.stringify throws on a bigint and writes a principal and a
blob in forms nobody reads, so the values a Reactor returns are written as
a DisplayReactor shows them:
- a
bigintas its decimal digits, in quotes:"100000000"; - a
Principalas its text,"aaaaa-aa", whereJSON.stringifywrites{"__principal__":"aaaaa-aa"}; - a
Uint8Array(ablob) as lowercase hex without0x,"0a0b", whereJSON.stringifywrites an object keyed by index,{"0":10,"1":11}; - any other typed array (a
vec nat16,vec int64, …) as an array of its numbers, abigintamong them as its digits.
Everything else is written as JSON.stringify(value, null, 2) writes it. The
text is for people: it does not say which strings were a bigint, a
principal or bytes, so it does not parse back into the value.
Parameters
Section titled “Parameters”unknown
The value to write, such as a call’s result.
Returns
Section titled “Returns”string
The value as JSON, indented by two spaces.
Example
Section titled “Example”import { jsonToString } from "@ic-reactor/core"import { Principal } from "@icp-sdk/core/principal"
jsonToString({ owner: Principal.fromText("aaaaa-aa"), subaccount: [new Uint8Array([1, 2])], amount: 5n,})// {// "owner": "aaaaa-aa",// "subaccount": [// "0102"// ],// "amount": "5"// }