Skip to content
/ arson Public

Efficient encoder and decoder for arbitrary objects

License

Notifications You must be signed in to change notification settings

benjamn/arson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arson, n.

the criminal act of deliberately setting fire to property

ARbitrary Structured Object Notation

JSON is great until you need to encode an object with circular references:

var obj = {};
obj.self = obj;
JSON.stringify(obj); // throws

Throwing an exception is lame, but even worse is muddling along as if everything is ok:

var a = {};
var b = { foo: 42 };
a.x = a.y = b;
var c = JSON.parse(JSON.stringify(a));
assert.strictEqual(c.x, c.y); // fails

We need an object notation that supports circular and repeated references.

That's where ARSON comes in:

var a = {};
var b = { foo: 42 };
a.x = a.y = b;
var c = ARSON.parse(ARSON.stringify(a));
assert.strictEqual(c.x, c.y); // no problem!

ARSON is compact, often even more compact than JSON, because repeated objects are defined only once:

var a = {};
var b = { foo: 42 };
a.x = a.y = b;
ARSON.stringify(a); // [{"x":1,"y":1},{"foo":2},42] vs.
                    // {"x":{"foo":42},"y":{"foo":42}}

About

Efficient encoder and decoder for arbitrary objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published