Skip to content

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.

Notifications You must be signed in to change notification settings

slowmove/json-tryparse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Json TryParse

Build Status

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

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages