I want to override JSON.stringify to use the json-stringify-safe module to avoid getting circular error.
Here is my code :
(function () {
const getSerialize = require('json-stringify-safe');
const stringifyCore = JSON.stringify;
JSON.stringify = (obj, replacer, spaces, cycleReplacer) => {
return stringifyCore.apply(this, [obj, getSerialize(replacer, cycleReplacer), spaces]);
};
}());
I also tried :
const getSerialize = require('json-stringify-safe');
const stringifyCore = JSON.stringify;
JSON.stringify = function (obj, replacer, spaces, cycleReplacer) {
return stringifyCore(obj, getSerialize(replacer, cycleReplacer), spaces);
};
I get an error :
Maximum call stack size exceeded
The solution eplanied here does not work for me.. Overriding JSON.stringify causing error
Any ideas?