
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Easily stringify and parse any object including objects with circular references, self references, dates, regexes, undefined, errors, and even functions
1, using the familar parse and stringify methods.
There are two ways to use this library, the first is to be able to
serialize without having to worry about circular references,
the second way is be able to handle dates, regexes, errors, functions
1, errors, and undefined (normally
JSON.stringify({ u: undefined }) === '{}')
The usage reflect these two approaches. If you just want to be
able to serialize an object then use jsan.stringify(obj),
if you want to JSON all the things then use it like
jsan.stringify(obj, null, null, true), the first three
arguments are the same as JSON.stringify (yup, JSON.stringify
takes three arguments)
Note that jsan.stringify(obj, null, null, true) will also deal
with circular references
var jsan = require('jsan');
var obj = {};
obj['self'] = obj;
obj['sub'] = {};
obj['sub']['subSelf'] = obj['sub'];
obj.now = new Date(2015, 0, 1);
var str = jsan.stringify(obj);
str === '{"self":{"$jsan":"$"},"sub":{"subSelf":{"$jsan":"$.sub"}},"now":"2015-01-01T05:00:00.000Z"}'; // true
var str2 = jsan.stringify(obj, null, null, true);
str2 === '{"self":{"$jsan":"$"},"sub":{"subSelf":{"$jsan":"$.sub"}},"now":{"$jsan":"d1420088400000"}}'; // true
var newObj1 = jsan.parse(str);
newObj1 === newObj1['self']; // true
newObj1['sub']['subSelf'] === newObj1['sub']; // true
typeof newObj1.now === 'string'; // true
var newObj2 = jsan.parse(str2);
newObj2 === newObj2['self']; // true
newObj2['sub']['subSelf'] === newObj2['sub']; // true
newObj2.now instanceof Date; // true
This ulitilty has been heavily optimized and performs as well as the native JSON.parse and
JSON.stringify, for usages of jsan.stringify(obj) when there are no circular references.
It does this by first try { JSON.stringify(obj) } and only when that fails, will it walk
the object. Because of this it won't property handle self references that aren't circular by
default. You can work around this by passing false as the fourth argument, or pass true and it
will also handle dates, regexes, undefeined, errors, and functions
var obj = { r: /test/ };
var subObj = {};
obj.a = subObj;
obj.b = subObj;
var str1 = jsan.stringify(obj) // '{"r":{},a":{},"b":{}}'
var str2 = jsan.stringify(obj, null, null, false) // '{"r":{},"a":{},"b":{"$jsan":"$.a"}}'
var str3 = jsan.stringify(obj, null, null, true) // '{"r":{"$jsan":"r,test"},"a":{},"b":{"$jsan":"$.a"}}'
You can't execute the functions after stringify() and parse(), they are just functions
that throw which have a toString() method similar to the original function
You can specify how and what should be handled by passing an object as the fourth argument:
var obj = { u: undefined, r: /test/, f: function bar() {} };
var str = jsan.stringify(obj, null, null, { undefined: true, function: true }); // '{"u":{"$jsan":"u"},"r":{},"f":{"$jsan":"ffunction bar() { /* ... */ }"}}'
The function property of options can also take a function which will be used as the
function stringifyer:
var obj = { u: undefined, r: /test/, f: function(x) { return x + 1 } };
var str = jsan.stringify(obj, null, null, {
undefined: true,
function: function(fn) { return fn.toString() }
});
str === '{"u":{"$jsan":"u"},"r":{},"f":{"$jsan":"ffunction (x) { return x + 1 }"}}'; // true
Flatted is a package that provides a way to serialize and deserialize JavaScript objects with circular references. It is similar to JSAN in that it handles circular references, but it uses a different approach by creating a custom JSON format. Flatted is often considered simpler and more lightweight compared to JSAN.
CircularJSON is another package designed to handle circular references in JavaScript objects. It is similar to JSAN in functionality, but it has been deprecated in favor of Flatted. CircularJSON was one of the earlier solutions for circular reference serialization, but it is less commonly used now.
json-stringify-safe is a package that provides a safe JSON.stringify alternative that can handle circular references by replacing them with a placeholder. Unlike JSAN, it does not attempt to fully preserve the structure of circular references, but it prevents errors during serialization.
FAQs
handle circular references when stringifying and parsing
The npm package jsan receives a total of 167,540 weekly downloads. As such, jsan popularity was classified as popular.
We found that jsan demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.