toStrictJsonValue
toStrictJsonValue(
value,sortKeys?):StrictJsonValue
Defined in: stableStringify.ts:39
Normalizes a value to the strict, portable JSON domain used for deterministic hashing, idempotency fingerprints, and cache key generation.
Enforces strict JSON boundaries:
- Primitives (
string,boolean,null, finitenumber) are preserved. - Dates are explicitly converted to ISO-8601 strings (
.toISOString()). - Custom objects with
.toJSON()methods are validated through their returned representation; internal fields excluded by that method are not inspected. - Object keys are optionally sorted recursively for deterministic serialization.
- Unsupported types (non-finite numbers,
Map,Set,Error,RegExp, binary buffers, promises, symbols, and sparse arrays) throw a TypeError. - Cyclic references are detected via a
WeakSetand throw a TypeError.
Parameters
Section titled “Parameters”unknown
The value to normalize.
sortKeys?
Section titled “sortKeys?”boolean = false
Whether to sort object keys recursively in lexicographical order.
Returns
Section titled “Returns”The strictly normalized JSON-compatible value.
Throws
Section titled “Throws”If the value contains cycles or elements outside the JSON domain.
Example
Section titled “Example”const normalized = toStrictJsonValue({ b: 2, a: 1 }, true);// → { a: 1, b: 2 }