{"id":21823254,"url":"https://github.com/orlandos-nl/bson","last_synced_at":"2026-04-01T19:47:13.432Z","repository":{"id":46878092,"uuid":"50234695","full_name":"orlandos-nl/BSON","owner":"orlandos-nl","description":"Native Swift library for BSON (http://bsonspec.org)","archived":false,"fork":false,"pushed_at":"2025-01-22T09:07:21.000Z","size":1466,"stargazers_count":114,"open_issues_count":4,"forks_count":34,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-01T23:45:06.174Z","etag":null,"topics":["bson","hacktoberfest","mongodb","server-side-swift","swift","swift-nio"],"latest_commit_sha":null,"homepage":"https://orlandos.nl/docs/mongokitten/articles/bson","language":"Swift","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/orlandos-nl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["joannis"]}},"created_at":"2016-01-23T10:56:07.000Z","updated_at":"2025-02-27T13:19:25.000Z","dependencies_parsed_at":"2023-07-13T09:24:54.496Z","dependency_job_id":"33064dd3-f6aa-4b8d-9415-9a28db91ab44","html_url":"https://github.com/orlandos-nl/BSON","commit_stats":{"total_commits":719,"total_committers":14,"mean_commits":"51.357142857142854","dds":0.4965229485396384,"last_synced_commit":"6056eae6adbc268963217a6c95a32a4dc4ee6884"},"previous_names":["openkitten/bson"],"tags_count":155,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlandos-nl%2FBSON","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlandos-nl%2FBSON/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlandos-nl%2FBSON/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orlandos-nl%2FBSON/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orlandos-nl","download_url":"https://codeload.github.com/orlandos-nl/BSON/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190250,"owners_count":20898702,"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":["bson","hacktoberfest","mongodb","server-side-swift","swift","swift-nio"],"created_at":"2024-11-27T17:21:54.796Z","updated_at":"2025-12-11T23:01:40.371Z","avatar_url":"https://github.com/orlandos-nl.png","language":"Swift","funding_links":["https://github.com/sponsors/joannis"],"categories":[],"sub_categories":[],"readme":"# BSON\n\nA fast BSON library, compliant to the whole BSON specification test suite. The library parses the binary data on-demand, delaying copies until the last second.\n\nBSON is parsed and generated as specified for version 1.1 of the [BSON specification](http://bsonspec.org/spec.html).\n\nBe sure to read our [full documentation](https://orlandos.nl/docs/mongokitten/articles/bson) and [API reference](https://swiftinit.org/reference/bson).\n\n## Installation\n\nBSON uses the Swift Package Manager. Add BSON to your dependencies in your Package.swift file:\n\n```swift\n.package(url: \"https://github.com/orlandos-nl/BSON.git\", from: \"8.0.0\")\n```\n\nAlso, don't forget to add \"BSON\" as a dependency for your target.\n\n## Basic Usage\n\nCreate Documents using Dictionary Literals:\n\n```swift\nvar userDocument: Document = [\n  \"username\": \"Joannis\",\n  \"online\": true,\n  \"age\": 20,\n  \"pi_constant\": 3.14,\n  \"profile\": [\n    \"firstName\": \"Joannis\",\n    \"lastName\": \"Orlandos\"\n  ]\n]\n\nlet favouriteNumbers: Document = [1, 3, 7, 14, 21, 24, 34]\n\nuserDocument[\"favouriteNumbers\"] = favouriteNumbers\n```\n\nAccess values in an array like you would in Swift Arrays and values in an object like a Dictionary.\n\n```swift\nlet favouriteNumber = favouriteNumbers[0]\nlet usernameValue = userDocument[\"username\"]\n```\n\nExtract types with simplicity:\n\n```swift\nlet username = String(userDocument[\"username\"]) // \"Joannis\"\nlet isOnline = Bool(userDocument[\"online\"]) // true\nlet age = Int(userDocument[\"age\"]) // 20\nlet pi = Double(userDocument[\"pi_constant\"]) // 3.14\n```\n\nChain subscripts easily to find results without a hassle as shown underneath using this JSON structure (assuming this is represented in BSON):\n\n```json\n{\n  \"users\": [\n    {\n      \"username\": \"Joannis\",\n      \"profile\": {\n        \"firstName\": \"Joannis\",\n        \"lastName\": \"Orlandos\"\n      }\n    },\n    {\n      \"username\": \"Obbut\",\n      \"profile\": {\n        \"firstName\": \"Robbert\",\n        \"lastName\": \"Brandsma\"\n      }\n    }\n  ]\n}\n```\n\n```swift\nlet obbutLastName = String(object[\"users\"][1][\"profile\"][\"lastName\"]) // \"Brandsma\"\n```\n\n### Nested Documents\n\nComplex array and dictionary literals may confuse the Swift type system. If this happens to you, make the literal explicitly a `Document` type:\n\n```swift\nvar userDocument: Document = [\n  \"username\": \"Joannis\",\n  \"online\": true,\n  \"age\": 20,\n  \"pi_constant\": 3.14,\n  \"profile\": [\n    \"firstName\": \"Joannis\",\n    \"lastName\": \"Orlandos\",\n    \"pets\": [\n        [\n          \"name\": \"Noodles\",\n          \"type\": \"Parrot\"\n        ] as Document,\n        [\n          \"name\": \"Witje\",\n          \"type\": \"Rabbit\"\n        ]\n      ] as Document\n    ] as Document\n]\n```\n\n### Codable\n\nDocument can be instantiated from [SwiftNIO](https://github.com/apple/swift-nio)'s `ByteBuffer` or `Foundation.Data`.\nYou can validate the formatting of this document manually using the `.validate()` function. This will also specify where the data was found corrupt.\n\nIf you pass a `Document` or `Primitive` into the `BSONDecoder` you can decode any `Decodable` type if the formats match. Likewise, `BSONEncoder` can encode your Swift types into a `Document`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlandos-nl%2Fbson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forlandos-nl%2Fbson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forlandos-nl%2Fbson/lists"}