2.1 KiB
2.1 KiB
json
Purpose
Safe JSON parse/stringify surface for the Suaveplan monorepo. Wraps the platform JSON global with prototype-pollution defense, AbortSignal handling, structured JsonError codes registered under the JSON.* namespace, OpenTelemetry spans, and a tryParse / isValidJSON / getStringifySize ergonomic layer that the platform global does not provide.
Package path: universal/data/json
Landed: 2026-04-20
Requirements
- R1 The package MUST expose
safeParse<T>(text, options?)that parses JSON and throwsJsonError(PARSE.FAILED)on invalid syntax. - R2
safeParseMUST reject keys in theforbiddenKeyslist (default:__proto__,constructor,prototype) withJsonError(PARSE.PROTOTYPE_POLLUTION). - R3
safeParseMUST accept anAbortSignaland throwJsonError(PARSE.FAILED)when the signal is already aborted before parsing begins. - R4 The package MUST expose
safeStringify(value, options?)that stringifies and throwsJsonError(STRINGIFY.CIRCULAR)on circular references. - R5
safeStringifyMUST allow DAG sharing (same object at multiple non-cyclic paths) without throwing. - R6
safeStringifyMUST accept anAbortSignaland throwJsonError(STRINGIFY.FAILED)when the signal is already aborted. - R7
safeStringifyMUST throwJsonError(STRINGIFY.FAILED)for any non-circular, non-JsonErrorexception fromJSON.stringify(e.g.BigInt). - R8 The package MUST expose
tryParse<T>(text, options?)that returnsundefinedinstead of throwing. - R9 The package MUST expose
isValidJSON(text)that returnstruefor the"null"literal (notfalseas a naïvetryParse() !== undefinedcheck would yield). - R10 The package MUST expose
getStringifySize(value)returning UTF-8 byte length ofJSON.stringify(value). - R11
safeParseandsafeStringifyMUST emit OpenTelemetry spans via@opentelemetry/api. - R12 All error codes MUST be registered under the
JSON.*namespace viadefineCodesfrom@suaveplan/error. - R13 Istanbul coverage on all 4 thresholds: 100%.
- R14 Docs coverage: 100%.