edgeport - v1.0.6
    Preparing search index...

    Function decodeJson

    • Parses JSON from UTF-8 bytes or a string.

      A one-call replacement for JSON.parse(new TextDecoder().decode(bytes)) that also accepts a string directly, and reports a bad payload as a uniform ProtocolError rather than a raw SyntaxError.

      Type Parameters

      • T = unknown

        The expected shape of the decoded value.

      Parameters

      • input: string | Uint8Array<ArrayBufferLike>

        The JSON payload, as UTF-8 bytes or a string.

      Returns T

      The parsed value.

      If the payload is not valid JSON.

      1.0.4

      import { decodeJson } from 'edgeport/util';

      decodeJson<{ ok: boolean }>(new TextEncoder().encode('{"ok":true}')); // { ok: true }