Reading MongoDB Exports: Extended JSON, $oid, $date and ObjectId Times
What $oid, $date, $numberLong and $numberDecimal mean in MongoDB exports, canonical versus relaxed Extended JSON, and the time inside an ObjectId.

Open a file made by mongoexport and you will see more braces than data: {"_id": {"$oid": "6720b8c1f1a2b3c4d5e6f701"}, "total": {"$numberDecimal": "149.90"}}. These wrappers are not noise. They keep the BSON types that plain JSON cannot express, so the data can be imported again without losing precision. This guide explains the format and shows how the MongoDB Extended JSON and ObjectId Viewer turns such files into a readable table.
Why Extended JSON exists
MongoDB stores documents in BSON, which has many more types than JSON. JSON has one number type, no dates and no binary data. If a 64-bit order number such as 9007199254740993 were written as a plain number, JavaScript would round it to 9007199254740992. If a price of 149.90 stored as Decimal128 became a JSON number, it would turn into a binary floating-point value. Extended JSON solves this by wrapping each special value in an object whose single key starts with a dollar sign.
The common wrappers
- $oid holds an ObjectId as 24 hexadecimal characters.
- $date holds a date, either as an ISO string or as milliseconds since 1970 inside $numberLong.
- $numberInt, $numberLong and $numberDouble keep the exact numeric type.
- $numberDecimal holds a Decimal128 value as a string, so no digits are lost.
- $binary holds binary data as Base64 with a subtype; subtype 04 is a UUID.
- $regularExpression, $timestamp, $minKey and $maxKey cover the rarer types.
Canonical and relaxed modes
Extended JSON version 2 has two modes. Canonical mode wraps everything, even small integers and doubles, so an Int32 and a Double stay distinct. It is the safest format for backups and for moving data between clusters. Relaxed mode is meant for people: ordinary numbers are written as JSON numbers and dates as ISO strings. Values that would lose precision, such as an Int64 above 2 to the power 53 or a date before 1970, stay wrapped even in relaxed mode.
The mongosh shell prints a third style that is not JSON at all: ObjectId('...'), ISODate('...'), Long('...') and keys without quotes. The viewer accepts all three, converts them to typed values and can write any of them back out.
The time inside an ObjectId
An ObjectId is 12 bytes. The first 4 are the creation time in seconds since 1970, the next 5 are a random value chosen once per process, and the last 3 are a counter. So the first 8 hexadecimal characters tell you when a document was inserted. For 6720b8c1f1a2b3c4d5e6f701, the prefix 6720b8c1 is 1730197697 seconds, which is 29 October 2024 at 10:28:17 UTC.
This also works backwards. The smallest ObjectId for a moment is its timestamp followed by sixteen zeros, and because _id is always indexed, a query such as _id greater than or equal to that value finds every document inserted after that time without a separate date field. The viewer's ObjectId tab builds that id and the query for any date you pick.
Mixed types
A column that holds more than one BSON type is a frequent source of confusion. MongoDB compares Int32, Int64, Double and Decimal128 by value, so numeric queries still work across them. But a price stored as the string "120" never matches a numeric condition, $type queries see each type separately, and Double values carry rounding errors that Decimal128 avoids. The viewer lists the types found in every column and warns about mixed columns as soon as a file is opened.
Working with an export
Drop a .json or .ndjson file into the viewer, or paste output from mongosh. A file can be a JSON array or one document per line, which is what mongoexport writes by default. If a line cannot be read, the viewer reports where it starts and loads the rest. The table shows nested fields as dot paths such as customer.name, colours values by type and opens the full document when you tap a row.
The filter box accepts a MongoDB condition such as {status: "paid", total: {$gte: 100}} or plain words for a quick text search. The convert tab writes canonical, relaxed, shell or plain JSON, as an array or one document per line. The CSV tab exports chosen fields in the same way as mongoexport --type=csv, with ObjectIds written as ObjectId(hex) and dates as ISO time.
When to use something else
The viewer is for reading and converting files, not for running database commands. To try find and aggregate pipelines on sample documents, use a query playground or a test database. For very large exports, use mongoexport with a query to take the slice you need before opening it in a browser.



