Loading BSON Minifier...

How to Minify BSON - Step by Step Guide

Step 1

Input Your BSON Data

BSON is the binary format MongoDB stores documents in. To get it onto this page you can:

•
Paste it: BSON bytes as Base64 or Hex, the way drivers, logs and API responses usually print them. Data URIs, URL-safe Base64 and 0x-prefixed hex dumps are fine.
•
Upload a file: Click "Upload" and pick a .bson or .bin file, for example one written by mongodump
•
Choose the format: Base64 or Hex, next to the input title. Pick the wrong one and the message tells you which one the text looks like.
•
Try the sample: Click "Sample" to load the document shown below

Example: BSON Input (Base64)

The sample is a 133-byte BSON document, written as Base64:

hQAAAAJjdXN0b21lcklkAAsAAABDVVNULTEyMzQ1AAJwaG9uZU51bWJlcgAOAAAAKzE1NTUtMTIzNDU2NwACcGxhblR5cGUADQAAAFVubGltaXRlZCA1RwASaWNjaWQARiiCMx2Ph3sQZGF0YVVzYWdlR0IALQAAAAhpc0FjdGl2ZQABAA==
Step 2

Automatic Decoding

About half a second after you stop typing, the bytes are decoded and written as Extended JSON on a single line.

•
No whitespace: keys and values follow each other with no spaces or line breaks
•
MongoDB types kept: ObjectId, Date, Binary and Decimal128 stay as $oid, $date, $binary and $numberDecimal
•
Exact long integers: 64-bit values such as the sample's ICCID keep every digit
•
Clear errors: a bad character is named with its line and column, and a cut-off document is reported as such
Step 3

Get the One-Line JSON

This is what the sample above turns into:

Minified JSON Output

{"customerId":"CUST-12345","phoneNumber":"+1555-1234567","planType":"Unlimited 5G","iccid":8901240544102066246,"dataUsageGB":45,"isActive":true}

144 characters, against 169 for the same JSON indented with two spaces, so the badge reads about 15% smaller.

Step 4

Export the JSON

•
Copy: puts the one-line JSON on the clipboard, ready for a request body, a test or MongoDB Compass
•
Download: saves the same text as bson-minified.json

What is BSON Minification?

BSON has no whitespace of its own, so "minifying" it really means decoding the binary document and writing it as the shortest JSON text that still carries every value. MongoDB-specific types travel as Extended JSON wrappers, and long integers are written out in full.

The result is the same data as the BSON Formatter shows, just without the indentation. If you would rather see the documents as rows and columns, try BSON to Table.

Frequently Asked Questions

What does "minifying BSON" actually mean here?

BSON itself is binary and has no whitespace to remove. This page decodes the BSON you paste or upload and writes it as Extended JSON on a single line, with no spaces or line breaks between keys and values. That one-line form is handy for log lines, test fixtures, curl bodies and anywhere a pretty-printed document would be in the way.

How much smaller is the output?

The badge compares the one-line JSON with the same JSON indented by two spaces, so you see the real saving for your data. For the sample document it is about 15%. Deeply nested documents save more, flat ones with long string values save less. It is not a comparison with the size of the BSON bytes.

Are long integers and MongoDB types kept?

Yes. A 64-bit value such as an ICCID 8901240544102066246 is written with every digit, not rounded the way JavaScript usually rounds big numbers. ObjectId, Date, Binary, Decimal128 and regular expressions keep their $oid, $date, $binary, $numberDecimal and $regularExpression wrappers, so a Decimal128 14.50 stays "14.50". Plain numbers come out as ordinary JSON numbers, which means the text no longer says whether a value was a BSON int32, int64 or double.

Can I minify a whole mongodump file?

Yes. A .bson file from mongodump holds documents written back to back. Upload it and you get a JSON array with one entry per document, all on one line. If the file is cut off or has stray bytes at the end, the message says which document is affected.

When should I use the formatter instead?

Use the minifier when the JSON goes into something else: a request body, a single log line, a fixture file. When you want to read the documents yourself, the BSON Formatter shows the same data indented, and BSON to Table lays it out as rows and columns.

Is my data uploaded anywhere?

No. Decoding and minifying happen in your browser and nothing you paste or upload is sent to our server. A reload starts with an empty editor. Very large files are limited by your browser memory and can take a few seconds.