Skip to content

scottcorgan/jsun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsun

Error catching JSON methods.

Hides away the try/catch madness for parsing strings and stringifying JSON objects.

Install

npm install jsun --save

Usage

var JSUN = require('jsun');

var validStr = JSUN.stringify({key: 'value'}).string;
var invalidStr = '<div></div>';

var validData = JSUN.parse(validStr);
console.log(validData.json) // {key: 'value'}
console.log(validData.err) // null

var invalidData = JSUN.parse(invalidStr);
console.log(invalidData.json) // null
console.log(invalidData.err) // error message from try/catch

Methods

parse(string)

Uses JSON.parse in a try/catch block

Returns:

{
  json: {} // some parsed string
  err: null // not null if there is an error
}

stringify(object)

Uses JSON.stringify in a try/catch block

Returns:

{
  string: {} // some stringified object
  err: null // not null if there is an error
}

Run Tests

npm install
npm test

About

Error catching JSON methods. Hides away the try/catch madness for parsing strings and stringifying JSON objects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published