1.1.0 • Published 8 years ago

json-back v1.1.0

Weekly downloads
16
License
MIT
Repository
github
Last release
8 years ago

json-back

JSON.parse() and .stringify() in callback passing style.

Usage

var JsonBack = require('json-back');

JsonBack.parse('{"a": 1, "b": 2}', function(error, result){
    // result === {a:1, b:2}
});

JsonBack.stringify({a:1, b:2}, function(error, result){
    // result === '{"a": 1, "b": 2}'
});

Errors

Parsing:

var JsonBack = require('json-back');

JsonBack.parse('{"a" 1, "b": 2}', function(error, result){
    // error instanceof SyntaxError
});

Stringifying:

var JsonBack = require('json-back');

var object = {};
object.cyclic = object;

JsonBack.stringify(object, function(error, result){
    error; -> 'Converting circular structure to JSON'
});

Also..

Reviver functions can be passed.

var JsonBack = require('json-back');

JsonBack.parse('{"a": 1, "b": 2}', reviverFn, function(error, result){
    // result === {a:1, b:2}
});

as can replacers and spacers.

var JsonBack = require('json-back');

JsonBack.parse('{"a": 1, "b": 2}', replacerFn, spacer, function(error, result){
    // result === {a:1, b:2}
});