百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

arson

> 编程语言
开源

适用于任意对象的高效编码器和解码器

198 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

适用于任意对象的高效编码器和解码器

arson

ARbitrary Structured Object Notation

Not to be confused with the criminal act of deliberately setting fire to property!

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

javascript
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:

javascript
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:

javascript
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:

javascript
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}}

But that's not all! ARSON can also encode undefined, thanks to the fact that [][-1] is always undefined:

javascript
> ARSON.encode({foo:undefined})
'[{"foo":-1}]'
> ARSON.decode(_)
{ foo: undefined }

It can also encode array holes:

javascript
> ARSON.encode(Array(3).concat([4, 5]))
'[[-2,-2,-2,1,2],4,5]'
> ARSON.decode(_)
[ , , , 4, 5 ]

Buffers:

javascript
> ARSON.encode(new Buffer("asdf"))
'[["Buffer","YXNkZg==","base64"]]'
> ARSON.decode(_)

Dates:

javascript
> ARSON.encode(new Date)
'[["Date","2016-02-02T00:25:36.886Z"]]'
> ARSON.decode(_)
Mon Feb 01 2016 19:25:36 GMT-0500 (EST)

RegExps:

javascript
> ARSON.encode(/asdf/img)
'[["RegExp","asdf","img"]]'
> ARSON.decode(_)
/asdf/gim

Sets:

javascript
> s = new Set
Set {}
> s.add(s)
Set { Set { Set { [Object] } } }
> ARSON.encode(s)
'[["Set",0]]'
> ARSON.decode(_)
Set { Set { Set { [Object] } } }
> _.has(_)
true

and Maps:

…

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言