JSON
Index
Functions
parse
Parse using
JSON.parse()and return aResult.const valid = '{ "a": true }';JSON.parse(valid); // Result.Ok({ a: true })const invalid = '{ "a": }';JSON.parse(invalid); // Result.Error(new SyntaxError('Unexpected token } in JSON at position 7'))
stringify
Convert to string using
JSON.stringify()and return aResultconst valid = { a: true };JSON.stringify(valid); // Result.Ok('{"a":true}')const circular = {get ref() {return this;},};JSON.stringify(circular);// Result.Error(new TypeError(...));
A collection of functions to encode/decode JSON. Instead of throwing errors like
globalThis.JSON, functions returnsResult