{"id":20513692,"url":"https://github.com/webreflection/jsonh","last_synced_at":"2025-05-16T06:08:07.345Z","repository":{"id":49767923,"uuid":"2226514","full_name":"WebReflection/JSONH","owner":"WebReflection","description":"Homogeneous Collection Compressor","archived":false,"fork":false,"pushed_at":"2017-07-24T06:32:58.000Z","size":58,"stargazers_count":640,"open_issues_count":1,"forks_count":71,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-05-16T06:07:54.137Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-08-18T07:01:47.000Z","updated_at":"2025-03-25T16:43:49.000Z","dependencies_parsed_at":"2022-08-30T15:41:15.513Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/JSONH","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2FJSONH","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2FJSONH/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2FJSONH/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2FJSONH/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/JSONH/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478193,"owners_count":22077676,"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-11-15T21:12:41.767Z","updated_at":"2025-05-16T06:08:02.331Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","readme":"[JSONH](http://webreflection.blogspot.com/2011/08/last-version-of-json-hpack.html) - JSON Homogeneous Collections Compressor\n============================================================================================================================\n\n[![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/WebReflection/donate)\n\nWhat is JSONH\n-------------\n\nJSONH is one of the most performant, yet safe, cross programming language, way to pack and unpack generic homogenous collections.\nBased on native or shimmed JSON implementation, JSONH is nothing different than a procedure performed right before `JSON.stringify(data)` or right after `JSON.parse(data)`\n\n[It is demonstrated](http://jsperf.com/jsonh/2) that overall performances of JSONH are up to 3 times faster in compression and 2 times in parsing thanks to smaller and simplified nature of the collection/string.\n\nIt is also demonstrated that resulting bandwidth size will be incrementally smaller than equivalent JSON operation reaching, in certain cases, down to 30% of original size and without gzip/deflate compression in place.\n\nJSONH is the latest version of [json.hpack](https://github.com/WebReflection/json.hpack) project and based on [JSONDB concept](http://michaux.ca/articles/json-db-a-compressed-json-format).\n\nNew in version 0.0.2 ( JS only )\n--------------------------------\n * added experimental and optional `schema` argument at the end of all methods in order to parse automatically one or more nested homogenous collections\n * covered via unit tests pack/unpack with or without the usage of a schema\n\n\nWhat is an Homogenous Collection\n--------------------------------\n\nUsually a database result set, stored as list of objects where all of them contains the same amount of keys with identical name.\nThis is a basic homogeneous collection example: \n```js\n[\n  {\"a\":\"A\",\"b\":\"B\"},\n  {\"a\":\"C\",\"b\":\"D\"},\n  {\"a\":\"E\",\"b\":\"F\"}\n]\n```\nWe all have exchange over the network one or more homogenous collections at least once.\nJSONH is able to pack the example into `[2,\"a\",\"b\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\"]` and unpack it into original collection at light speed.\n\n\nJSONH is suitable for\n---------------------\n\n * runtime data compression with or without gzip/deflate on both client and server side\n * creation of static JavaScript files to serve in order to save space on Hard Drive and eventually make runtime gzip/deflate compression easier (smaller input)\n * send huge collection of data from the client to the server and improving performances over `JSON.stringify(data)` and required network bandwidth\n\nIf the generic object/data contains one or more homogenous collections, JSONH is suitable for these cases too via `pack` and `unpack` operations.\nPlease read the [related post](http://webreflection.blogspot.com/2011/08/jsonh-and-hybrid-js-objects.html) to know more.\n\n\nJSONH API\n---------\nEvery implementation is suitable for the programming language code style and every method supports original JSON signature.\nAs example the JavaScript version is a global `JSONH` object with `stringify`, `parse`, `pack`, and `unpack` methods.\n\nThe python version is a module similar to `json` one with current methods: `dump`, `dumps`, `load`, `loads`, `pack`, and `unpack`.\n\n    import jsonh\n    \n    print(jsonh.dumps(\n        [{\"a\": \"A\", \"b\": \"B\"}, {\"a\": \"C\", \"b\": \"D\"}, {\"a\": \"E\", \"b\": \"F\"}],\n        separator = (',',':')\n    ))\n\n\nThe php 5 version is a static class plus some function in order to let developers decide for their favorite stile.\nExtra arguments accepted by `json_encode` and `json_decode` are supported as well.\n\n    require_once('JSONH.class.php');\n    \n    // classic style\n    jsonh_encode($object); // jsonh_decode($str)\n    \n    // static public style\n    JSONH::stringify($object); // JSONH::parse($str);\n    \n    // singleton style\n    JSONH()-\u003estringify($object); // JSONH()-\u003eparse($str)\n    \n\n\nTODO\n----\n\n * clean up locally tests and use a standard one able to cover all aspects per each implementation\n * C# version, and hopefully with other developers help other languages too\n * simplified yet cross platform way to *map* hybrid objects, specifying via white list one or more nested properties to `pack` on stringify, and `unpack` on parse (automated and addressed compression for complex objects)\n\nJavaScript And Native JSON Escape Problems\n------------------------------------------\nAs [@garethheyes](https://twitter.com/garethheyes) pointed out by in [this post](http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/), native `JSON.stringify(data)` may produce invalid JavaScript.\nSince JSONH aim is *not* to change native JSON behavior, neither is JSONH a replacement for JSON, all I can suggest is to perform this replacement when and if data could be corrupted:\n\n    JSONH.stringify(data).replace(\n        /\\u2028|\\u2029/g,\n        function (m) {\n            return \"\\\\u202\" + (m === \"\\u2028\" ? \"8\" : \"9\");\n        })\n\nThis will ensure proper escape for those characters plus performances will be still better thanks to reduced string output size (compared with the equivalent operation performed by `JSON.stringify(data)`).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fjsonh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fjsonh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fjsonh/lists"}