{"name":"jsan","version":"3.0.0","description":"handle circular references when stringifying and parsing","main":"index.js","scripts":{"test":"mocha"},"keywords":["json"],"author":{"name":"Moshe Kolodny"},"license":"MIT","devDependencies":{"circular-json":"^0.3.0","json-stringify-safe":"^5.0.1","mocha":"^2.2.1"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/kolodny/jsan.git"},"bugs":{"url":"https://github.com/kolodny/jsan/issues"},"homepage":"https://github.com/kolodny/jsan","gitHead":"09a6795d241aaa66031e065726a384b9c2463203","_id":"jsan@3.0.0","_shasum":"75dd245edda5a388343ff10d31aad4fb5a12f1bd","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.5.0","_npmUser":{"name":"kolodny","email":"kolodny.github@gmail.com"},"dist":{"shasum":"75dd245edda5a388343ff10d31aad4fb5a12f1bd","tarball":"http://registry-npm.ywwl.com/jsan/download/jsan-3.0.0.tgz","integrity":"sha512-isOGt4/RehqCCARfb+lR9lh2T44Zh88PFhGhBhEilm74qN+6k+Odi5i7SSU7waFQiBXjjlVFKpIVvMD6PEDyTQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDR3tQWTW7s69MDsD1hMPvjI0Vt3TDyd3fUNXznw/GougIhAPmdh8y+N5+ALu612gc/mNcEdShdK9HHhzOBM79lP2SZ"}],"size":7553,"noattachment":false,"key":"/jsan/-/jsan-3.0.0.tgz"},"maintainers":[{"name":"kolodny","email":"kolodny.github@gmail.com"}],"_npmOperationalInternal":{"host":"packages-5-east.internal.npmjs.com","tmp":"tmp/jsan-3.0.0.tgz_1456804019083_0.15673732105642557"},"directories":{},"readme":"jsan\n===\n\n[![Build Status](https://travis-ci.org/kolodny/jsan.svg?branch=master)](https://travis-ci.org/kolodny/jsan)\n\n### JavaScript \"All The Things\" Notation  \n![jsan](https://i.imgur.com/IdKDIB6.png)\n\nEasily stringify and parse any object including objects with circular references, self references, dates, regexes, `undefined`, errors, and even functions\n<sub>[1](#functions)</sub>, using the familar `parse` and `stringify` methods.\n\nThere are two ways to use this library, the first is to be able to\nserialize without having to worry about circular references,\nthe second way is be able to handle dates, regexes, errors, functions\n<sub>[1](#functions)</sub>, errors, and undefined (normally\n`JSON.stringify({ u: undefined }) === '{}'`)\n\nThe usage reflect these two approaches. If you just want to be\nable to serialize an object then use `jsan.stringify(obj)`,\nif you want to JSON all the things then use it like\n`jsan.stringify(obj, null, null, true)`, the first three\narguments are the same as `JSON.stringify` (yup, `JSON.stringify`\ntakes three arguments)\n\nNote that `jsan.stringify(obj, null, null, true)` will also deal\nwith circular references\n\n\n### Usage\n\n```js\nvar jsan = require('jsan');\n\nvar obj = {};\nobj['self'] = obj;\nobj['sub'] = {};\nobj['sub']['subSelf'] = obj['sub'];\nobj.now = new Date(2015, 0, 1);\n\nvar str = jsan.stringify(obj);\nstr === '{\"self\":{\"$jsan\":\"$\"},\"sub\":{\"subSelf\":{\"$jsan\":\"$.sub\"}},\"now\":\"2015-01-01T05:00:00.000Z\"}'; // true\nvar str2 = jsan.stringify(obj, null, null, true);\nstr2 === '{\"self\":{\"$jsan\":\"$\"},\"sub\":{\"subSelf\":{\"$jsan\":\"$.sub\"}},\"now\":{\"$jsan\":\"d1420088400000\"}}'; // true\n\nvar newObj1 = jsan.parse(str);\nnewObj1 === newObj1['self']; // true\nnewObj1['sub']['subSelf'] === newObj1['sub']; // true\ntypeof newObj1.now === 'string'; // true\n\nvar newObj2 = jsan.parse(str2);\nnewObj2 === newObj2['self']; // true\nnewObj2['sub']['subSelf'] === newObj2['sub']; // true\nnewObj2.now instanceof Date; // true\n```\n\n#### Notes\n\nThis ulitilty has been heavily optimized and performs as well as the native `JSON.parse` and\n`JSON.stringify`, for usages of `jsan.stringify(obj)` when there are no circular references. \nIt does this by first `try { JSON.stringify(obj) }` and only when that fails, will it walk\nthe object. Because of this it won't property handle self references that aren't circular by\ndefault. You can work around this by passing false as the fourth argument, or pass true and it\nwill also handle dates, regexes, `undefeined`, errors, and functions\n\n```js\nvar obj = { r: /test/ };\nvar subObj = {};\nobj.a = subObj;\nobj.b = subObj;\nvar str1 = jsan.stringify(obj) // '{\"r\":{},a\":{},\"b\":{}}'\nvar str2 = jsan.stringify(obj, null, null, false) // '{\"r\":{},\"a\":{},\"b\":{\"$jsan\":\"$.a\"}}'\nvar str3 = jsan.stringify(obj, null, null, true) // '{\"r\":{\"$jsan\":\"r,test\"},\"a\":{},\"b\":{\"$jsan\":\"$.a\"}}'\n```\n\n##### Functions\n\nYou can't execute the functions after `stringify()` and `parse()`, they are just functions\nthat throw which have a `toString()` method similar to the original function\n\n### Advance Usage\n\nYou can specify how and what should be handled by passing an object as the fourth argument:\n\n```js\nvar obj = { u: undefined, r: /test/, f: function bar() {} };\nvar str = jsan.stringify(obj, null, null, { undefined: true, function: true }); // '{\"u\":{\"$jsan\":\"u\"},\"r\":{},\"f\":{\"$jsan\":\"ffunction bar() { /* ... */ }\"}}'\n```\n\nThe `function` property of options can also take a function which will be used as the\nfunction stringifyer:\n\n```js\nvar obj = { u: undefined, r: /test/, f: function(x) { return x + 1 } };\nvar str = jsan.stringify(obj, null, null, {\n  undefined: true,\n  function: function(fn) { return fn.toString() }\n});\nstr === '{\"u\":{\"$jsan\":\"u\"},\"r\":{},\"f\":{\"$jsan\":\"ffunction (x) { return x + 1 }\"}}'; // true\n```\n","publish_time":1456804020988,"_cnpm_publish_time":1456804020988,"dist-tags":{"latest":"3.1.14"}}