stringify-safe
Discover why you can't JSON.stringify(your_object) and automaticly remove the causes.
Installation
npm i stringify-safe
Usage
.fixStringify()
Basic Usage
const StringifySafe =
StringifySafe checks if JSON.stringify(your_object)
fails.
With .fixStringify()
the causes will be recursively determined and removed.
var fixedObject = StringifySafe
Recursion Depth
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 = 5var fixedObject = StringifySafe
Printing
If you want to see wich childs fail to get stringified, set printing
to true
.
The default is false
.
// depth = 6// printing = truevar fixedObject = StringifySafe
.stringify()
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
.isBroken()
This function tells you if your object is broken by returning a boolean.
var isBroken = StringifySafe
.hasBrokenChilds()
This function tells you if your object contains broken childs by returning a boolean.
var hasBrokenChilds = StringifySafe