The decode path
Read BSON once, then work with ordinary document values.
The loader decodes BSON directly without an external backend. Application code receives the decoded document and can decide whether to inspect, transform, or re-encode it.
Input
BSON binary document bytes
Output
JSON-like JavaScript object values
Types
Dates, int64, decimal128, bytes, and nested documents
Options
Native decode and nesting options
Detailed guide
BSONLoader reference
The sections below document installation, usage, native options and decoded value representations.
BSONLoader loads BSON binary documents into JSON-like JavaScript objects.
Installation
BSON decoding and encoding are implemented natively; no bson package is needed.
npm install @loaders.gl/core @loaders.gl/documents
Install @loaders.gl/documents. Its root contains metadata; use flat subpaths for implementations.
Usage
import {load} from '@loaders.gl/core';
import {BSONLoader} from '@loaders.gl/documents';
const data = await load(url, BSONLoader, {bson: options});
BSONLoader Options
| Option | Default | Behavior |
|---|---|---|
bson.concatenatedDocuments | 'error' | Reject concatenated dump documents, or use 'first' to decode only the first. |
bson.promoteLongs | true | Return safe int64 values as numbers; unsafe values remain bigint. Set false for tagged int64 values. |
bson.useBigInt64 | false | Return int64 values as bigint, overriding promoteLongs. |
bson.preserveTypes | false | Preserve double, int32, and int64 wire types using native scalar markers; takes precedence over integer promotion. |
bson.maxDepth | 100 | Maximum document/array nesting, including the root and JavaScript code scopes. |
Strings are strictly validated as UTF-8. Invalid lengths, terminators, array indexes, boolean values, unknown element types, and reads outside nested document boundaries are rejected. Duplicate document keys use the last value. Prototype-sensitive keys remain ordinary own properties and never modify object prototypes. Stored code and regex patterns are not executed.
Value representations
See the native BSON value contract.
For synchronous parsing, import BSONLoaderWithParser from
@loaders.gl/documents/bson and pass it to parseSync.
