Skip to content
Sealpaste

MongoDB Extended JSON ↔ JSON

Paste a document from mongosh, Compass or mongoexport and get plain JSON, or turn plain JSON into Extended JSON ready for mongoimport.

Direction

Extended JSON or mongosh output

Plain JSON

How to use it

  1. 1Choose the direction.
  2. 2Paste a document or an array. mongosh syntax (ObjectId('…'), ISODate(…), unquoted keys, single quotes) is accepted.
  3. 3For JSON → EJSON, choose relaxed or canonical and which strings become ObjectIds and dates.

Private by design

Everything runs in this browser tab. Your input is never uploaded, logged or saved on a server, and there are no public "recent" pages. Close the tab and it's gone.

How we keep it private

Examples

mongosh output to plain JSON

Decimal128 becomes a string so no cents are lost.

Input

{ _id: ObjectId('65f1c0a8e4b0a1b2c3d4e5f6'), total: NumberDecimal('149.90'), createdAt: ISODate('2024-03-13T15:05:12Z') }

Output

{
  "_id": "65f1c0a8e4b0a1b2c3d4e5f6",
  "total": "149.90",
  "createdAt": "2024-03-13T15:05:12.000Z"
}
Plain JSON to relaxed EJSON

Input

{"_id": "65f1c0a8e4b0a1b2c3d4e5f6", "createdAt": "2024-03-13T15:05:12Z"}

Output

{
  "_id": { "$oid": "65f1c0a8e4b0a1b2c3d4e5f6" },
  "createdAt": { "$date": "2024-03-13T15:05:12Z" }
}

How BSON types become plain JSON

BSON / shellPlain JSON
ObjectId("…")"65f1c0a8…" (hex string)
ISODate("…") / $date"2024-03-13T15:05:12.000Z" (ISO string)
NumberInt, NumberLong, Doublenumber (exact, also beyond 2^53)
NumberDecimal / $numberDecimal"149.90" (string, keeps precision)
UUID("…") / Binary subtype 4"0e5e4d7f-…" (UUID string)
BinData / $binaryBase64 string
Timestamp(t, i){"t": …, "i": …}
/regex/i"/regex/i"

Relaxed vs canonical Extended JSON

Relaxed mode writes numbers as plain JSON numbers and dates as ISO strings inside {"$date": …}; it is readable and what Compass and mongoexport use by default.

Canonical mode wraps every number with its exact type ({"$numberInt": "5"}, {"$numberDouble": "1.5"}) so a round trip through JSON keeps int vs double vs long exactly. Use it when types matter, e.g. for fixtures and migrations.

Sources: MongoDB Extended JSON v2 spec

Frequently asked questions

Why can’t JSON.parse read my mongosh output?

mongosh prints JavaScript, not JSON: unquoted keys, single quotes and helpers like ObjectId(…) and ISODate(…). This converter understands that syntax and turns it into real JSON.

Which strings become ObjectIds in JSON → EJSON?

24-character hex strings in _id, id and fields ending in Id or _id (customerId, user_id). Other hex-looking strings stay strings. Turn the option off to keep every string as is.

Is my data sent to a server or a database?

No. Conversion uses the official bson library running in your browser. Nothing is uploaded.