BSON - Maple Help

BSON (.bson) File Format

BSON file format

Description

 • BSON (Binary JSON) is a binary data standard for describing structured data made of key-value pairs, lists, and various scalar data types, inspired by the JSON standard.
 • The general-purpose commands Import and Export permit parsing and generating BSON files and expressions.
 Specifically, BSON byte arrays are mapped to Arrays and and BSON date/time values are mapped to Time objects.

Notes

 • Content-Type: application/bson

Examples

Parse a BSON string as an expression.

 > $\mathrm{byteArr}≔\mathrm{Array}\left(\left[19,0,0,0,16,120,0,-116,0,0,0,16,121,0,-79,-1,-1,-1,0\right],\mathrm{datatype}=\mathrm{integer}\left[1\right]\right)$
 ${\mathrm{byteArr}}{≔}\left[\begin{array}{ccccccccccccccccccc}{19}& {0}& {0}& {0}& {16}& {120}& {0}& {-116}& {0}& {0}& {0}& {16}& {121}& {0}& {-79}& {-1}& {-1}& {-1}& {0}\end{array}\right]$ (1)
 > $\mathrm{Import}\left(\mathrm{byteArr},\mathrm{format}="BSON",\mathrm{source}=\mathrm{direct}\right)$
 ${table}{}\left(\left[{"y"}{=}{-79}{,}{"x"}{=}{140}\right]\right)$ (2)

Import data from a file in BSON format.

 > $\mathrm{UNDHR}≔\mathrm{Import}\left("example/UNDHR.bson",\mathrm{base}=\mathrm{datadir}\right)$
 ${\mathrm{UNDHR}}{≔}{table}{}\left(\left[{"event"}{=}{"United Nations Declaration of Human Rights"}{,}{"location"}{=}{table}{}\left(\left[{"country"}{=}{"France"}{,}{"city"}{=}{"Paris"}{,}{"address"}{=}{"1 Place du Trocadéro et du 11 Novembre"}{,}{"name"}{=}{"Palais de Chaillot"}\right]\right){,}{"ratification"}{=}{\mathrm{}}\right]\right)$ (3)
 > $\mathrm{Date}\left(\mathrm{UNDHR}\left["ratification"\right]\right)$
 ${\mathrm{}}$ (4)

Export data to a BSON file in the home directory of the current user.

 > $\mathrm{Mouse}≔\mathrm{table}\left(\left["Genus"="Mus","Species"="musculus"\right]\right)$
 ${\mathrm{Mouse}}{≔}{table}{}\left(\left[{"Genus"}{=}{"Mus"}{,}{"Species"}{=}{"musculus"}\right]\right)$ (5)
 > $\mathrm{Mouse}\left["Family"\right]≔"Muridae"$
 ${{\mathrm{Mouse}}}_{{"Family"}}{≔}{"Muridae"}$ (6)
 > $\mathrm{Mouse}\left["Order"\right]≔"Rodentia"$
 ${{\mathrm{Mouse}}}_{{"Order"}}{≔}{"Rodentia"}$ (7)
 > $\mathrm{Mouse}\left["Class"\right]≔"Mammalia"$
 ${{\mathrm{Mouse}}}_{{"Class"}}{≔}{"Mammalia"}$ (8)
 > $\mathrm{Export}\left("mouse.bson",\mathrm{Mouse},\mathrm{base}=\mathrm{homedir}\right)$
 ${81}$ (9)