Function jsonUnwrapStringify

  • Stringify, which ensures concordium domain types are unwrapped to their inner type before stringified. This should be used if you want to manually deserialize the inner property values, as the serialization is irreversible.

    Deprecated

    Manually convert the object to the preferred JSON structure instead. For account transactions, use AccountTransactionHandler.toJSON prior to invoking JSON.stringify. It's up to the developer to handle serialization of bigints, e.g. with the json-bigint dependency.

    Example

    jsonUnwrapStringify(100n) => throws TypeError, as bigints cannot be serialized. jsonUnwrapStringify(100n, BigintFormatType.None) => throws TypeError jsonUnwrapStringify(100n, BigintFormatType.None, (_key, value) => 'replaced') => '"replaced"'

    jsonUnwrapStringify(100n, BigintFormatType.Number) => '100' jsonUnwrapStringify(100n, BigintFormatType.Number, (_key, value) => -value) => '-100' // runs both replacer and bigintFormat jsonUnwrapStringify(100n, BigintFormatType.Number, (_key, value) => 'replaced') => '"replaced"' // replacer takes precedence

    jsonUnwrapStringify(100n, BigintFormatType.String) => '"100"' jsonUnwrapStringify(100n, BigintFormatType.String, (_key, value) => -value) => '"-100"' // runs both replacer and bigintFormat jsonUnwrapStringify(100n, BigintFormatType.String, (_key, value) => 10) => '10' // replacer takes precedence

    Parameters

    • input: any
    • bigintFormat: BigintFormatType = BigintFormatType.None

      Determines how to handle bigints. Can be set to either:

      • BigintFormatType.Number: uses 'json-bigint to safely serialize,
      • BigintFormatType.String: converts bigint to strings
      • BigintFormatType.None: must be taken care of manually, e.g. in replacer function. Defaults to BigintFormatType.None
    • Optional replacer: ReplacerFun

      A function that transforms the results. This overrides bigintFormat, and will also run on primitive values passed as value.

    • Optional space: string | number

      Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

    Returns string

Generated using TypeDoc