Like JSON stringify/parse, but never throws on circular references and BigInt values.
npm install calmer-jsonconst text = toJson(value, options?)valueValue to stringify to a JSON textoptions.replacer?Function to transform value entries (if any)options.space?String to use to ident or number of spaces for identationoptions.onError?Callback to handle possible errors and provide a fallback value
Unlike JSON.stringify, toJson never throws on circular references or BigInt values. It just ignores them as non-serializable:
const example = {
circular: null,
bigint: BigInt('1'),
foo: 'bar',
};
example.circular = example;
toJson(example); // -> '{"foo":"bar"}'const value = fromJson(text, options?)textString to parse from JSON text to a valueoptions.reviver?Function to transform value entries (if any)options.onError?Callback to handle possible errors and provide a fallback value