# @deepkit/bson

> Deepkit BSON parser

Latest version **1.1.0** (published 2026-10-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @deepkit/bson
pnpm add @deepkit/bson
yarn add @deepkit/bson
bun add @deepkit/bson
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2026-10-31 |
| First published | 2020-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 782.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3549 |
| Author | Marc J. Schmidt |
| Maintainers | marcj |

## Links

- npm: https://www.npmjs.com/package/@deepkit/bson
- Repository: https://github.com/deepkit/deepkit-framework
- Homepage: https://github.com/deepkit/deepkit-framework#readme
- Issues: https://github.com/deepkit/deepkit-framework/issues
- npm.io page: https://npm.io/package/@deepkit/bson

## Recent versions

- 1.1.0 (latest) — 2026-10-31
- 1.0.19 — 2025-09-22
- 1.0.18 — 2025-09-22
- 1.0.15 — 2025-06-26
- 1.0.12 — 2025-06-05
- 1.0.11 — 2025-06-02
- 1.0.9 — 2025-05-23
- 1.0.8 — 2025-05-20
- 1.0.7 — 2025-04-18
- 1.0.5 — 2025-04-02
- 1.0.3 — 2025-03-13
- 1.0.2 — 2025-02-24
- 1.0.1 — 2025-02-24
- 1.0.1-alpha.160 — 2025-02-18
- 1.0.1-alpha.158 — 2025-02-15
- … 129 more at https://npm.io/package/@deepkit/bson/versions

## README

# BSON

`@deepkit/bson` is a high-performance TS implementation of a parser and serializer for BSON,
 the MongoDB Binary JSON format. It's the fastest JS BSON parser, even faster than native JSON.parse/stringify.
 
Deepkit has reimplemented it because it's a high-performance framework and both the official JS (js-bson) and C++ (bson-ext) packages are too slow. 
How slow? When converting 10k elements in an array, js-bson takes 25ms, bson-ext takes 31ms, whiles JSON.parse takes only 5ms. 
This makes the official BSON parser 5x slower than native JSON.parse. deepkit/type-bson on the other hand takes only 2ms and is therefore 13x faster.

### Benchmark

**Parsing** BSON buffer that contains an array with 10k objects.

| Method | Time (ms) |
| ------ | --------: |
| official native bson-ext |  31ms | 
| official js-bson |  25ms | 
| deepkit/bson generic v2 |  6ms | 
| deepkit/bson generic v3 |  4ms | 
| JSON.parse |  5ms | 
| deepkit/type JIT | 2ms |


**Serializing** an array with 10k objects.

| Method | Time (ms) |
| ------ | --------: |
| official native bson-ext |  39ms | 
| official js-bson |  33ms | 
| JSON.stringify |  5ms | 
| deepkit/bson JIT | 2ms |

"deepkit/bson JIT" means a parser/serializer based on a schema like so:

```typescript
import {t} from '@deepkit/type';
import {getBSONDecoder} from '@deepkit/bson';

interface Model {
    username: string;
    tags: string[];
    priority: number;
}

const decoder = getBSONDecoder<Model>();
const bson = new Buffer([]);

const document = decoder(bson);
``` 

whereas "deepkit/type generic" means schema-less:

```typescript
import {parseObject, ParserV2, ParserV3} from '@deepkit/bson';
const bson = new Buffer([]);

const object1 = parseObject(new ParserV2(bson));

const object2 = parseObject(new ParserV3(bson));
```

### Differences

There are a couple of differences to the official serializer.

- ObjectId is deserialized as string.
- UUID is deserialized as string.
- BigInt is supported and serialized as long. 
- Unlimited size BigInt supported (serialised as binary)
- Long is deserialized as BigInt.

---
_Source: https://npm.io/package/@deepkit/bson · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
