Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Feb 26, 2024 via pnpm

bson 5.1.0

A bson parser for node.js and the browser
Package summary
Share
0
issues
1
license
1
Apache-2.0
Package created
13 Apr 2011
Version published
16 Mar 2023
Maintainers
8
Total deps
1
Direct deps
0
License
Apache-2.0

Issues

0
This package has no issues

Licenses

Apache License 2.0

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
use-patent-claims
place-warranty
Cannot
hold-liable
use-trademark
Must
include-copyright
include-license
state-changes
include-notice
1 Packages, Including:
bson@5.1.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of bson 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does bson do?

BSON, an acronym for "Binary JSON," provides a binary-encoded serialization of JSON-like documents. Being used as a library, it allows the efficient encoding of data in binary format that is easy to manipulate, making storage and network transfer more efficient. It is a useful tool that adds to the performance of applications that frequently serialize and un-serialize data for storage or transfer.

How do you use bson?

To utilize BSON, there are different approaches for Node.js and browsers. For a Node.js environment or when using a bundler, following are the steps:

Firstly, you need to install the package:

npm install bson

Once the package is installed, you can proceed with the import and usage as illustrated below:

import { BSON, EJSON, ObjectId } from 'bson';
// const { BSON, EJSON, ObjectId } = require('bson') also works

// create a BSON serialized object
const bytes = BSON.serialize({ _id: new ObjectId() });
console.log(bytes);

// decode the BSON object back to JSON-like document
const doc = BSON.deserialize(bytes);
console.log(EJSON.stringify(doc));

If working directly in the browser, without a bundler, you can use the .mjs bundle like so:

<script type="module">
  import { BSON, EJSON, ObjectId } from './lib/bson.mjs';

  // create a BSON serialized object
  const bytes = BSON.serialize({ _id: new ObjectId() });
  console.log(bytes);

  // decode the BSON object back to JSON-like document
  const doc = BSON.deserialize(bytes);
  console.log(EJSON.stringify(doc));
</script>

Note: In both cases, an ObjectId is being serialized and logged, then it's being deserialized and logged again in a JSON-like document format.

Where are the bson docs?

BSON official documentation can be found here. It includes detailed guides and specifications on various BSON module components like BSON, EJSON features including methods for BDSOn processing such as .parse, .stringify, .serialize, and .deserialize.