{"id":15631258,"url":"https://github.com/benjamn/arson","last_synced_at":"2025-04-12T19:48:26.063Z","repository":{"id":50377506,"uuid":"50610465","full_name":"benjamn/arson","owner":"benjamn","description":"Efficient encoder and decoder for arbitrary objects","archived":false,"fork":false,"pushed_at":"2018-11-02T16:08:29.000Z","size":30,"stargazers_count":196,"open_issues_count":3,"forks_count":5,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-12T19:48:24.424Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benjamn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-28T20:13:09.000Z","updated_at":"2024-12-19T21:33:33.000Z","dependencies_parsed_at":"2022-09-19T15:50:30.885Z","dependency_job_id":null,"html_url":"https://github.com/benjamn/arson","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjamn%2Farson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjamn%2Farson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjamn%2Farson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjamn%2Farson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benjamn","download_url":"https://codeload.github.com/benjamn/arson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625500,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T10:39:42.228Z","updated_at":"2025-04-12T19:48:26.045Z","avatar_url":"https://github.com/benjamn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# arson [![Build Status](https://travis-ci.org/benjamn/arson.svg?branch=master)](https://travis-ci.org/benjamn/arson) [![Greenkeeper badge](https://badges.greenkeeper.io/benjamn/arson.svg)](https://greenkeeper.io/)\n\n### *AR*bitrary *S*tructured *O*bject *N*otation\n\n_Not to be confused with the criminal act of deliberately setting fire to property!_\n\n[JSON](http://www.json.org/) is great until you need to encode an object with circular references:\n```js\nvar obj = {};\nobj.self = obj;\nJSON.stringify(obj); // throws\n```\n\nThrowing an exception is lame, but even worse is muddling along as if everything is ok:\n```js\nvar a = {};\nvar b = { foo: 42 };\na.x = a.y = b;\nvar c = JSON.parse(JSON.stringify(a));\nassert.strictEqual(c.x, c.y); // fails\n```\n\nWe need an object notation that supports circular and repeated references.\n\nThat's where `ARSON` comes in:\n```js\nvar a = {};\nvar b = { foo: 42 };\na.x = a.y = b;\nvar c = ARSON.parse(ARSON.stringify(a));\nassert.strictEqual(c.x, c.y); // no problem!\n```\n\n`ARSON` is compact, often even more compact than JSON, because repeated objects are defined only once:\n```js\nvar a = {};\nvar b = { foo: 42 };\na.x = a.y = b;\nARSON.stringify(a); // [{\"x\":1,\"y\":1},{\"foo\":2},42] vs.\n                    // {\"x\":{\"foo\":42},\"y\":{\"foo\":42}}\n```\n\nBut that's not all! `ARSON` can also encode `undefined`, thanks to the fact that `[][-1]` is always `undefined`:\n```js\n\u003e ARSON.encode({foo:undefined})\n'[{\"foo\":-1}]'\n\u003e ARSON.decode(_)\n{ foo: undefined }\n```\n\nIt can also encode array *holes*:\n```js\n\u003e ARSON.encode(Array(3).concat([4, 5]))\n'[[-2,-2,-2,1,2],4,5]'\n\u003e ARSON.decode(_)\n[ , , , 4, 5 ]\n```\n\n`Buffer`s:\n```js\n\u003e ARSON.encode(new Buffer(\"asdf\"))\n'[[\"Buffer\",\"YXNkZg==\",\"base64\"]]'\n\u003e ARSON.decode(_)\n\u003cBuffer 61 73 64 66\u003e\n```\n\n`Date`s:\n```js\n\u003e ARSON.encode(new Date)\n'[[\"Date\",\"2016-02-02T00:25:36.886Z\"]]'\n\u003e ARSON.decode(_)\nMon Feb 01 2016 19:25:36 GMT-0500 (EST)\n```\n\n`RegExp`s:\n```js\n\u003e ARSON.encode(/asdf/img)\n'[[\"RegExp\",\"asdf\",\"img\"]]'\n\u003e ARSON.decode(_)\n/asdf/gim\n```\n\n`Set`s:\n```js\n\u003e s = new Set\nSet {}\n\u003e s.add(s)\nSet { Set { Set { [Object] } } }\n\u003e ARSON.encode(s)\n'[[\"Set\",0]]'\n\u003e ARSON.decode(_)\nSet { Set { Set { [Object] } } }\n\u003e _.has(_)\ntrue\n```\n\nand `Map`s:\n```js\n\u003e m = new Map\nMap {}\n\u003e m.set(1234, m)\nMap { 1234 =\u003e Map { 1234 =\u003e Map { 1234 =\u003e [Object] } } }\n\u003e m.set(m, 5678)\nMap {\n  1234 =\u003e Map {\n    1234 =\u003e Map {\n      1234 =\u003e [Object],\n      [Object] =\u003e 5678\n    },\n    Map {\n      1234 =\u003e [Object],\n      [Object] =\u003e 5678\n    } =\u003e 5678\n  },\n  Map {\n    1234 =\u003e Map {\n      1234 =\u003e [Object],\n      [Object] =\u003e 5678\n    },\n    Map {\n      1234 =\u003e [Object],\n      [Object] =\u003e 5678\n    } =\u003e 5678\n  } =\u003e 5678\n}\n\u003e ARSON.encode(m)\n'[[\"Map\",1,2],[3,0],[0,4],1234,5678]'\n\u003e ARSON.decode(_)\nMap {\n  1234 =\u003e Map {\n    1234 =\u003e Map {\n      1234 =\u003e [Object],\n      [Object] =\u003e 5678\n    },\n    Map {\n      1234 =\u003e [Object],\n      [Object] =\u003e 5678\n    } =\u003e 5678\n  },\n  Map {\n    1234 =\u003e Map {\n      1234 =\u003e [Object],\n      [Object] =\u003e 5678\n    },\n    Map {\n      1234 =\u003e [Object],\n      [Object] =\u003e 5678\n    } =\u003e 5678\n  } =\u003e 5678\n}\n\u003e _.get(_.get(1234)) === 5678\ntrue\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjamn%2Farson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenjamn%2Farson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjamn%2Farson/lists"}