{"version":3,"file":"json.mjs","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,yCAAyC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAA2B,IAAY;IAC9D,OAAO,WAAW,CAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAW,EAAE,MAAM,GAAG,KAAK;IAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,kGAAkG;IAClG,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;AAC1E,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n  return getSafeJson<Type>(JSON.parse(json));\n}\n\n/**\n * Get the size of a JSON blob without validating that is valid JSON.\n *\n * This may sometimes be preferred over `getJsonSize` for performance reasons.\n *\n * Note: By default this function does not encode the string to bytes, thus the input may\n * be about 4x larger in practice. Use this function with caution.\n *\n * @param value - The JSON value to get the size of.\n * @param encode - Whether the value should be encoded before measuring.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSizeUnsafe(value: Json, encode = false): number {\n  const json = JSON.stringify(value);\n  // We intentionally don't use `TextEncoder` by default because of bad performance on React Native.\n  return encode ? new TextEncoder().encode(json).byteLength : json.length;\n}\n"]}