npm install json-tryparse
A small extension of the native JSON class to have methods that can handle a parse or stringify even if the object already are one or another.
In projects where there are several developers working we've often been in situation where everybody doesn't know if the object passing around after we've called some api is the parsed json object or the stringified object as string.
To be able to handle this I've implemented a simple extension of the native JSON class.
require('json-tryparse');Instead of
JSON.parse(variable);use
JSON.tryParse(variable);Instead of
JSON.stringify(variable);use
JSON.tryStringify(variable);npm test