{"id":24605422,"url":"https://github.com/lennartcl/jsonm","last_synced_at":"2025-05-05T16:44:56.364Z","repository":{"id":57145584,"uuid":"48959173","full_name":"lennartcl/jsonm","owner":"lennartcl","description":"json compressor for packing messages with memoization","archived":false,"fork":false,"pushed_at":"2023-02-28T08:23:36.000Z","size":242,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-01T14:48:00.242Z","etag":null,"topics":["compression","javascript","json","jsonm","memoization","nodejs","websocket"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/jsonm","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/lennartcl.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-03T20:11:34.000Z","updated_at":"2024-08-06T05:27:03.000Z","dependencies_parsed_at":"2024-06-20T00:06:35.265Z","dependency_job_id":"a51341ca-2d38-4ff4-a5c0-5769c9462c47","html_url":"https://github.com/lennartcl/jsonm","commit_stats":{"total_commits":90,"total_committers":4,"mean_commits":22.5,"dds":"0.16666666666666663","last_synced_commit":"d6218b8d2011f19b197e6e272f8c16123f59e1a4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennartcl%2Fjsonm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennartcl%2Fjsonm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennartcl%2Fjsonm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lennartcl%2Fjsonm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lennartcl","download_url":"https://codeload.github.com/lennartcl/jsonm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252535496,"owners_count":21763965,"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":["compression","javascript","json","jsonm","memoization","nodejs","websocket"],"created_at":"2025-01-24T16:17:23.508Z","updated_at":"2025-05-05T16:44:56.346Z","avatar_url":"https://github.com/lennartcl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"jsonm\n=====\n\n_\"Listen very carefully, I shall say 'zis only once!\"_\n\njsonm is a fast and safe way to compress JSON messages using memoization.\njsonm makes messages up to several orders of magnitude smaller by getting rid\nof repeated names and values.\n\njsonm is best friends with **websocket** libraries like [socket.io](http://socket.io/).\nModern browsers can **gzip** messages sent over websockets, and jsonm can make them\neven smaller for maximum responsiveness of web applications.\n\n## Installation\n\n```\n$ npm install --save jsonm\n```\n\nIn the client, jsonm works well with webpack or browserify.\nOur npm distribution also includes a prepackaged client-side version in build/jsonm.js.\n\n## Compression Examples\n\njsonm packs\n\n```\n[\n    { \"firstName\": \"Francis\", \"lastName\": \"Doe\", \"address\": \"Callison Lane 2775, Wilmington\" },\n    { \"firstName\": \"Anna\", \"lastName\": \"Smith\", \"address\": \"Callison Lane 2775, Wilmington\" },\n    { \"firstName\": \"Agent\", \"lastName\": \"Smith\", \"address\": \"Callison Lane 2775, Wilmington\", \"isAlias\": true },\n    { \"firstName\": \"Anna\", \"lastName\": \"Francis\", \"address\": \"Callison Lane 2776, Wilmington\" }\n]\n```\n\ninto \n\n```\n[0,\n    [\"firstName\", \"lastName\", \"address\", \"Francis\", \"Doe\", \"Callison Lane 2775, Wilmington\"],\n    [3, 4, 5, \"Anna\", \"Smith\", 8],\n    [3, 4, 5, \"isAlias\", \"Agent\", 10, 8, true],\n    [3, 4, 5, 9, 6, \"Callison Lane 2776, Wilmington\"]\n]\n```\n\nNotice how it eliminates all common substrings like `\"firstName\"` using memoization!\njsonm keeps a dictionary to compress future messages even further. \nSend the original message above a second time, and it becomes:\n\n```\n[0,[3,4,5,6,7,8],[3,4,5,9,10,8],[3,4,5,11,12,10,8,13],[3,4,5,9,6,14]]\n```\n\nNow let's consider a different message:\n\n```\n[\n    { \"firstName\": \"Bryan\", \"lastName\": \"Fuller\" },\n    { \"firstName\": \"Anna\", \"lastName\": \"Adams\" },\n    { \"firstName\": \"Tim\", \"lastName\": \"Peterson\" },\n    { \"firstName\": \"Francis\", \"lastName\": \"Peterson\" }\n]\n```\n\nthis becomes\n\n```\n[0,[3,4,\"Bryan\",\"Fuller\"],[3,4,9,\"Adams\"],[3,4,\"Tim\",\"Peterson\"],[3,4,6,23]]\n```\n\nBy avoiding repetition, jsonm can for example help decrease the size of messages\nsent from a web server to the client. It effectively leaves out all information\nthe client already knows about.\n\n## Usage\n\njsonm is designed for sending messages between a sender and a receiver.\nThe sender packs messages and the receiver unpacks them.\n\n_Sender, packing a message:_\n\n```\nconst packer = new jsonm.Packer();\nlet packedMessage = packer.pack(message);\n```\n\n_Receiver, unpacking a message:_\n\n```\nconst unpacker = new jsonm.Unpacker();\nlet message = unpacker.unpack(packedMessage);\n```\n\nBoth the packer and unpacker maintain a stateful dictionary. Don't lose them!\nCreate a new packer for each new connection, or use `packer.reset()` to\nreset the dictionary of an existing packer.\n\n### Working with Strings\n\njsonm provides `packString()` for dealing with messages in string form.\n\n`packString()` can be used to efficiently pack multi-line strings. For\nexample, a string `\"foo\\nbar\"` is packed as if `[\"foo\", \"bar\"]` was packed:\n\n```\nlet packed = packer.packString(\"foo\\nbar\");\nunpacker.unpack(packed); // returns \"foo\\nbar\"\n```\n\n`packString()` can also efficiently pack JSON objects in string format,\ninternally parsing and stringifying them:\n\n```\nlet packed = packer.packString('{\"foo\":\"bar\"}');\nunpacker.unpack(packed); // returns '{\"foo\":\"bar\"}'\n```\n\n## Related Projects\n\n- JSONC: https://github.com/tcorral/JSONC\n- JSONH: https://github.com/WebReflection/JSONH\n- JSONR: https://github.com/dogada/RJSON\n\nThese projects pack uniform JavaScript objects, eliminating the\nneed for repeating the keys of each object. As an example, JSONH can pack\n\n```\n[\n    { \"firstName\": \"John\", \"lastName\": \"Doe\", \"isAlias\": false },\n    { \"firstName\": \"Anna\", \"lastName\": \"Smith\", \"isAlias\": false },\n    { \"firstName\": \"Agent\", \"lastName\": \"Smith\", \"isAlias\": true }\n]\n```\n\ninto\n\n```\n[3,\"firstName\",\"lastName\",\"isAlias\",\"John\",\"Doe\",false,\"Anna\",\"Smith\",false,\"Agent\",\"Smith\",true]\n```\n\nJSONC, JSONH, and JSONR don't apply memoization and only help with uniform data\nor data with a recurring scheme. Unlike jsom, however, they are stateless, which\ncan make it easier to use them in some cases.\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flennartcl%2Fjsonm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flennartcl%2Fjsonm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flennartcl%2Fjsonm/lists"}