json-tryparse
v1.0.5
Published
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.
Downloads
17
Readme
Json TryParse
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.
Background
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.
Usage
require('json-tryparse');
Parsing to object
Instead of
JSON.parse(variable);
use
JSON.tryParse(variable);
Stringify
Instead of
JSON.stringify(variable);
use
JSON.tryStringify(variable);
Run tests
npm test