BSON (.bson)

Background

    JSON-like binary serialization.
    Schemaless format.
    Represent document as ordered key/value pairs.
    Format used to store data in MongoDB.
    BSON is specified at http://bsonspec.org.

Import and Export

  • Import["file.bson"] imports a BSON file as an association.
  • ImportString["string","BSON"] imports a BSON string of bytes.
  • Export["file",assoc,"BSON"] exports an association to a BSON file.
  • ExportString[assoc,"BSON"] exports to a BSON string of bytes.
  • The "BSON" format identifies BSON documents with associations of the Wolfram Language.
  • The MongoDB database stores data as BSON documents.
  • A BSON document is a list of key/value pairs. The keys of the association must be strings, and values must be one of the following types:
  • BSONObjectIDObjectId
    Associationobject
    ByteArraybinary data
    DateObjectdate
    Infinitymax key
    Integer64-bit integer
    Listarray
    Minus[Infinity]min key
    Nullnull
    Realdouble
    Stringstring
    True,FalseBoolean

Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties and settings

Examples

Basic Examples  (2)

Export an association as a BSON document:

In[1]:=
Click for copyable input

Import the resulting string of bytes as an expression:

In[2]:=
Click for copyable input
Out[2]=

DateObject is supported in the BSON format:

In[1]:=
Click for copyable input

Import as an expression:

In[2]:=
Click for copyable input
Out[2]=

See Also

"RawJSON"  "ExpressionJSON"  "JSON"  "UBJSON"