nosj
v1.0.1
Published
JSON serializer and deserializer for simple JSON objects.
Downloads
38
Maintainers
Readme
nosj
JSON serializer and deserializer for simple JSON objects.
Install
$ npm install --save nosj
Usage
var nosj = require('nosj');
var obj = {
string: 'hello',
number: 13,
float: 3.14,
date: new Date('01/13/1982'),
array: [
{a: 'a'},
{b: 'b'}
],
object: {
x: 'x',
y: 'y'
}
};
nosj.serialize(obj);
//=> {"string":"hello","number":13,"float":3.14,"date":"1982-01-13T05:00:00.000Z","array":[{"a":"a"},{"b":"b"}],"object":{"x":"x","y":"y"}}
var string = '{"string":"hello","number":13,"float":3.14,"date":"1982-01-13T05:00:00.000Z","array":[{"a":"a"},{"b":"b"}],"object":{"x":"x","y":"y"}}'
nosj.deserialize(string);
//=>
// {
// string: 'hello',
// number: 13,
// float: 3.14,
// date: Wed Jan 13 1982 00:00:00 GMT-0500 (EST),
// array: [ { a: 'a' }, { b: 'b' } ],
// object: { x: 'x', y: 'y' }
// }
API
serialize(object)
Serialize a string back into JSON
deserialize(string, [options])
Deserialize a string back into JSON
options
stringToDates
Type: boolean
Default: true
Convert all ISO 8601 date formatted strings to a Date
.
License
MIT © Blain Smith