Discover why you can't JSON.stringify(your_object) and automaticly remove the causes.
npm i stringify-safeconst StringifySafe = require('stringify-safe')StringifySafe checks if JSON.stringify(your_object) fails.
With .fixStringify() the causes will be recursively determined and removed.
var fixedObject = StringifySafe.fixStringify(brokenObject)You can manually set a maximal recusion depth.
The default is 10.
0 means recursion and if your brokenObject is broken {} will be returned.
// depth = 5
var fixedObject = StringifySafe.fixStringify(brokenObject, 5)If you want to see wich childs fail to get stringified, set printing to true.
The default is false.
// depth = 6
// printing = true
var fixedObject = StringifySafe.fixStringify(brokenObject, 5 true)This function is a warpper for .fixStringify(), but it direclty JSON.stringify(your_object) you object.
The parametrs are working like .fixStringify().
var fixedStrigifiedObject = StringifySafe.stringify(brokenObject)This function tells you if your object is broken by returning a boolean.
var isBroken = StringifySafe.isBroken(your_object)This function tells you if your object contains broken childs by returning a boolean.
var hasBrokenChilds = StringifySafe.hasBrokenChilds(your_object)