{"id":17067783,"url":"https://github.com/kstenerud/bonjson","last_synced_at":"2025-07-07T08:34:32.172Z","repository":{"id":233119531,"uuid":"786089978","full_name":"kstenerud/bonjson","owner":"kstenerud","description":"A lightning-fast and efficient 1:1 compatible binary drop-in replacement for JSON","archived":false,"fork":false,"pushed_at":"2025-04-06T21:35:05.000Z","size":75,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-06T22:26:16.718Z","etag":null,"topics":["binary","json","serialization"],"latest_commit_sha":null,"homepage":"","language":null,"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/kstenerud.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-13T11:53:54.000Z","updated_at":"2025-04-06T21:35:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"1c9f13c3-55ae-4aa8-bd1c-205a9c71786c","html_url":"https://github.com/kstenerud/bonjson","commit_stats":null,"previous_names":["kstenerud/bonjson"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kstenerud/bonjson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstenerud%2Fbonjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstenerud%2Fbonjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstenerud%2Fbonjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstenerud%2Fbonjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kstenerud","download_url":"https://codeload.github.com/kstenerud/bonjson/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kstenerud%2Fbonjson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264043340,"owners_count":23548545,"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":["binary","json","serialization"],"created_at":"2024-10-14T11:11:38.375Z","updated_at":"2025-07-07T08:34:32.167Z","avatar_url":"https://github.com/kstenerud.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"BONJSON: Binary Object Notation for JSON\n========================================\n\nBONJSON is a _hardened_, _lightning-fast_ and _efficient_, **1:1 compatible** binary drop-in replacement for [JSON](#json-standards).\n\nIt's **35 times** faster to process than [JSON](#json-standards).\n\nIt's also **far safer** than JSON:\n\n* **Safe** against key collision attacks\n* **Safe** against injection attacks\n* **Safe** against truncation attacks\n* **Safe** against numeric range attacks\n\n\nWhy use binary?\n---------------\n\n### Efficiency\n\nText formats are great for humans to read, but they're slow and wasteful for computers.\n\n**35 times** slower than they could be in this case!\n\nComputers should speak to humans in **text** (such as [JSON](#json-standards)), and to each other in **binary**.\n\n\n\nWhy use BONJSON?\n----------------\n\n### It's Small\n\n* The [BONJSON specification](bonjson.md) is only 800 lines long (including the formal grammar).\n* The [C reference implementation](https://github.com/kstenerud/ksbonjson/tree/main/library/src) is less than 500 LOC each for the encoder and decoder.\n\n### It's Simple\n\n* It doesn't use tricks like histograms or references or lookups. Leave those to _real_ compression algorithms.\n* It uses existing, CPU-native data encodings as much as possible.\n* It keeps tricky sub-byte data to a minimum.\n\n### It's Safe\n\n* **Safe** against key collision attacks\n* **Safe** against injection attacks\n* **Safe** against truncation attacks\n* **Safe** against numeric range attacks\n\n### It's Speedy\n\n* Data encoding and decoding can be done using branchless algorithms ([example](https://github.com/kstenerud/ksbonjson/tree/main/library/src)).\n* The most common data types and ranges are encoded in fewer bytes.\n* The [C reference implementation](https://github.com/kstenerud/ksbonjson) is **35 times** faster than [jq](https://github.com/jqlang/jq).\n\nBenchmarking [the C Reference Implementation](https://github.com/kstenerud/ksbonjson) vs [jq](https://github.com/jqlang/jq) on a Core i3-1315U (using [this test data](https://github.com/kstenerud/test-data)):\n\n**10MB:**\n\n```\n~/ksbonjson/benchmark$ ./benchmark.sh 10mb\n\nBenchmarking BONJSON (decode+encode) with 9052k file 10mb.boj\n\nreal    0m0.021s\nuser    0m0.009s\nsys     0m0.016s\n\nBenchmarking BONJSON (decode only) with 9052k file 10mb.boj\n\nreal    0m0.011s\nuser    0m0.003s\nsys     0m0.012s\n\nBenchmarking JSON (decode+encode) with 10256k file 10mb.json\n\nreal    0m0.340s\nuser    0m0.322s\nsys     0m0.024s\n```\n\nBONJSON processed **35.8x** faster.\n\n**100MB:**\n\n```\n~/ksbonjson/benchmark$ ./benchmark.sh 100mb\n\nBenchmarking BONJSON (decode+encode) with 90508k file 100mb.boj\n\nreal    0m0.183s\nuser    0m0.085s\nsys     0m0.121s\n\nBenchmarking BONJSON (decode only) with 90508k file 100mb.boj\n\nreal    0m0.080s\nuser    0m0.030s\nsys     0m0.071s\n\nBenchmarking JSON (decode+encode) with 102560k file 100mb.json\n\nreal    0m3.227s\nuser    0m3.039s\nsys     0m0.232s\n```\n\nBONJSON processed **35.8x** faster.\n\n**1000MB:**\n\n```\n~/ksbonjson/benchmark$ ./benchmark.sh 1000mb\n\nBenchmarking BONJSON (decode+encode) with 905076k file 1000mb.boj\n\nreal    0m1.762s\nuser    0m0.846s\nsys     0m1.124s\n\nBenchmarking BONJSON (decode only) with 905076k file 1000mb.boj\n\nreal    0m0.746s\nuser    0m0.300s\nsys     0m0.645s\n\nBenchmarking JSON (decode+encode) with 1025564k file 1000mb.json\n\nreal    0m31.522s\nuser    0m29.737s\nsys     0m2.307s\n```\n\nBONJSON processed **35.2x** faster.\n\n\n\nWhat about the other binary JSON-like formats?\n----------------------------------------------\n\n**None** of them are 1:1 compatible. None of them are safe. Most of them are overcomplicated.\n\n| Encoding | Type Parity | Value Parity | Feature Parity | Safety | Endianness |\n| -------- | ----------- | ------------ | -------------- | ------ | ---------- |\n| BONJSON  |      ✔️     |      ✔️      |        ✔️       |   ✔️   |   Little   |\n| BSON     |      ❌     |      ❌      |        ❌       |   ❌   |   Little   |\n| CBOR     |      ❌     |      ❌      |        ❌       |   ❌   |   Big      |\n| UBJSON   |      ✔️     |      ❌      |        ❌       |   ❌   |   Big      |\n| BJData   |      ❌     |      ❌      |        ❌       |   ❌   |   Little   |\n| PSON     |      ❌     |      ❌      |        ❌       |   ❌   |   Little   |\n| Msgpack  |      ❌     |      ❌      |        ❌       |   ❌   |   Big      |\n| Smile    |      ❌     |      ❌      |        ❌       |   ❌   |   Big      |\n\n* **Type Parity**: No extra data types that aren't present in [JSON](#json-standards)\n* **Value Parity**: Allows only the same value ranges as [JSON](#json-standards) (for example: infinities and NaN are disallowed)\n* **Feature Parity**: Supports the same features as [JSON](#json-standards) (for example: progressive document construction)\n* **Safety**: Guards against common attack vectors (key collisions, truncation, range)\n* **Endianness**: Big endian formats are slower to process on modern hardware\n\n**Wherever there's a compatibility mismatch, breakage will eventually occur** - it's only a matter of time before your complex data pipelines trigger it.\n\nHaving confidence in your data plumbing is paramount.\n\n\n-------------------------------------------------------------------------------\n\n📚 Specifications and Code\n--------------------------\n\n### Specification\n\n * [📖 BONJSON Specification](bonjson.md)\n\n### Formal Grammar\n\n * [🔡 Dogma grammar for BONJSON](bonjson.dogma)\n\n### Implementations\n\n * [⚙️ C Reference Implementation](https://github.com/kstenerud/ksbonjson)\n\n-------------------------------------------------------------------------------\n\n\nJSON Standards\n--------------\n\nAny discussions about JSON are done within the context of the ECMA and RFC specifications for JSON, and the json.org website:\n\n * [ECMA-404](https://ecma-international.org/publications-and-standards/standards/ecma-404/)\n * [RFC 8259](https://www.rfc-editor.org/info/rfc8259)\n * [json.org](https://www.json.org)\n\n\n\nLicense\n-------\n\nCopyright (c) 2024 Karl Stenerud. All rights reserved.\n\nDistributed under the [Creative Commons Attribution License](https://creativecommons.org/licenses/by/4.0/legalcode) ([license deed](https://creativecommons.org/licenses/by/4.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkstenerud%2Fbonjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkstenerud%2Fbonjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkstenerud%2Fbonjson/lists"}