{"id":17786158,"url":"https://github.com/dcodeio/pson","last_synced_at":"2025-04-05T07:07:50.021Z","repository":{"id":9470460,"uuid":"11354940","full_name":"dcodeIO/PSON","owner":"dcodeIO","description":"A super efficient binary serialization format for JSON.","archived":false,"fork":false,"pushed_at":"2017-09-20T14:38:04.000Z","size":568,"stargazers_count":458,"open_issues_count":12,"forks_count":34,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-04-14T13:21:41.090Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://dcode.io/PSON","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dcodeIO.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":"2013-07-11T22:42:18.000Z","updated_at":"2024-04-12T14:45:46.000Z","dependencies_parsed_at":"2022-09-05T05:00:45.062Z","dependency_job_id":null,"html_url":"https://github.com/dcodeIO/PSON","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2FPSON","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2FPSON/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2FPSON/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2FPSON/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcodeIO","download_url":"https://codeload.github.com/dcodeIO/PSON/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299833,"owners_count":20916190,"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-27T09:04:54.451Z","updated_at":"2025-04-05T07:07:49.992Z","avatar_url":"https://github.com/dcodeIO.png","language":"JavaScript","readme":"![PSON](https://raw.github.com/dcodeIO/PSON/master/PSON.png)\n====\n**PSON** is a super efficient binary serialization format for JSON focused on minimal encoding size.\n\nHow does it work?\n-----------------\nPSON combines the best of JSON, BJSON, ProtoBuf and a bit of ZIP to achieve a superior small footprint on the network\nlevel. Basic constants and small integer values are efficiently encoded as a single byte. Other integer values are always\nencoded as variable length integers. Additionally it comes with progressive and static dictionaries to reduce data\nredundancy to a minimum. In a nutshell:\n\n* 246 single byte values\n* Base 128 variable length integers (varints) as in protobuf\n* 32 bit floats instead of 64 bit doubles if possible without information loss\n* Progressive and static dictionaries\n* Raw binary data support\n* Long support\n\nReference implementation\n------------------------\nThis repository contains a plain **node.js/CommonJS, RequireJS/AMD and Browser compatible** JavaScript implementation\nof the [PSON specification](https://github.com/dcodeIO/PSON/blob/master/PSONspec.txt) on top of \n[ByteBuffer.js](https://github.com/dcodeIO/ByteBuffer.js) and optionally [Long.js](https://github.com/dcodeIO/Long.js):\n\nA **PSON.StaticPair** contains the PSON encoder and decoder for a static (or empty) dictionary and can be shared between\nall connections. It's recommended for production.\n\nA **PSON.ProgressivePair** contains the PSON encoder and decoder for a progressive (automatically filling) dictionary.\nOn the one hand this requires no dictionary work from the developer but on the other requires one pair per connection.\n\ntl;dr Numbers, please!\n----------------------\nThe test suite contains the following basic example message:\n\n```json\n{\n    \"hello\": \"world!\",\n    \"time\": 1234567890,\n    \"float\": 0.01234,\n    \"boolean\": true,\n    \"otherbool\": false,\n    \"null\": null,\n    \"obj\": {\n        \"what\": \"that\"\n    },\n    \"arr\": [1,2,3]\n}\n```\n\n* **JSON** stringify: 133 bytes\n* **PSON** without a dictionary: 103 bytes (about **22% smaller** than JSON)\n* **PSON** with a progressive dictionary: 103 bytes for the first and 59 bytes for each subsequent message (about \n  **22% smaller** for the first and about **55% smaller** for each subsequent message than JSON.\n* **PSON** with the same but static dictionary: 59 bytes for each message (about **55% smaller** than JSON)\n         \n```text\n F6 08 FE 00 FC 06 77 6F 72 6C 64 21 FE 01 F8 A4   ......world!....\n 8B B0 99 79 FE 02 FB F6 0B 76 C3 B6 45 89 3F FE   ...y.....v..E.?.\n 03 F1 FE 04 F2 FE 05 F0 FE 06 F6 01 FE 07 FC 04   ................\n 74 68 61 74 FE 08 F7 03 02 04 06                  that.......\n```\n\nAnother example that's also contained in the test suite is encoding our package.json, which is of course a string value\ncentered file, to PSON using a general purpose static dictionary:\n\n* **JSON** stringify: 813 bytes\n* **PSON** with empty dict: 760 bytes (about **6% smaller** than JSON)\n* **PSON** with [static dict](https://github.com/dcodeIO/PSON/blob/master/dicts/package.json): 613 bytes (about **24% smaller** than JSON)\n\nUsage\n-----\n\n#### node.js/CommonJS\n\n`npm install pson`\n\n```js\nvar PSON = require(\"pson\");\n...\n```\n\n#### RequireJS/AMD\n\n```js\nrequire.config({\n    ...\n    \"paths\": {\n        \"Long\": \"/path/to/Long.js\", // optional\n        \"ByteBuffer\": \"/path/to/ByteBufferAB.js\",\n        \"PSON\": \"/path/to/PSON.js\"\n    },\n    ...\n});\nrequire([\"PSON\"], function(PSON) {\n    ...\n});\n```\n\n#### Browser\n\n```html\n\u003cscript src=\"Long.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"ByteBufferAB.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"PSON.min.js\"\u003e\u003c/script\u003e\n```\n\n```js\nvar PSON = dcodeIO.PSON;\n...\n```\n\nExample\n-------\n```js\n// Sender\nvar initialDictionary = [\"hello\"];\nvar pson = new PSON.ProgressivePair(initialDictionary);\nvar data = { \"hello\": \"world!\" };\nvar buffer = pson.encode(data);\nsomeSocket.send(buffer);\n```\n\n```js\n// Receiver\nvar initialDictionary = [\"hello\"];\nvar pson = new PSON.ProgressivePair(initialDictionary);\nsomeSocket.on(\"data\", function(data) {\n    data = pson.decode(data);\n    ...\n});\n```\n\nAPI\n---\nThe API is pretty much straight forward:\n\n* `PSON.Pair#encode(json: *): ByteBuffer` encodes JSON to PSON data\n  * `PSON.Pair#toBuffer(json: *): Buffer` encodes straight to a node.js Buffer\n  * `PSON.Pair#toArrayBuffer(json: *): ArrayBuffer` encodes straight to an ArrayBuffer\n* `PSON.Pair#decode(pson: ByteBuffer|Buffer|ArrayBuffer): *` decodes PSON data to JSON\n\n#### Progressive\n* `new PSON.ProgressivePair([initialDictionary: Array.\u003cstring\u003e])` constructs a new progressive encoder and decoder pair\n  with an automatically filling keyword dictionary\n* `PSON.ProgressivePair#exclude(obj: Object)` Excludes an object's and its children's keywords from being added to the progressive\n   dictionary\n* `PSON.ProgressivePair#include(obj: Object)` Undoes the former\n\n#### Static\n* `new PSON.StaticPair([dictionary: Array.\u003cstring\u003e])` constructs a new static encoder and decoder pair\n  with a static (or empty) dictionary\n  \nDownloads\n---------\n* [Distributions](https://github.com/dcodeIO/PSON/tree/master/dist)\n* [ZIP-Archive](https://github.com/dcodeIO/PSON/archive/master.zip)\n* [Tarball](https://github.com/dcodeIO/PSON/tarball/master)\n  \nDocumentation\n-------------\n* [PSON specification](https://github.com/dcodeIO/PSON/blob/master/PSONspec.txt)\n* [API documentation](http://htmlpreview.github.io/?http://raw.github.com/dcodeIO/PSON/master/docs/PSON.html)\n\n**License:** [Apache License, Version 2.0](http://opensource.org/licenses/Apache-2.0)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcodeio%2Fpson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcodeio%2Fpson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcodeio%2Fpson/lists"}