UBJSON (.ubj) File Format - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Input and Output : File Formats : Formats/UBJSON

UBJSON (.ubj) File Format

UBJSON file format

Description

 • UBJSON (Universal Binary JSON) is a binary data standard for describing structured data made of key-value pairs and lists based on the JSON standard.
 • The general-purpose commands Import and Export permit parsing and generating UBJSON files and expressions.

Notes

 • Content-Type: application/ubjson

Examples

Parse a UBJSON string as an expression.

 > $\mathrm{byteArr}≔\mathrm{Array}\left(\left[123,35,105,2,105,1,120,85,-116,105,1,121,105,-79\right],\mathrm{datatype}=\mathrm{integer}\left[1\right]\right)$
 ${\mathrm{byteArr}}{≔}\left[\begin{array}{cccccccccccccc}{123}& {35}& {105}& {2}& {105}& {1}& {120}& {85}& {-116}& {105}& {1}& {121}& {105}& {-79}\end{array}\right]$ (1)
 > $\mathrm{Import}\left(\mathrm{byteArr},\mathrm{format}="UBJSON",\mathrm{source}=\mathrm{direct}\right)$
 ${table}{}\left(\left[{"y"}{=}{-79}{,}{"x"}{=}{140}\right]\right)$ (2)

Import data from a file in UBJSON format.

 > $\mathrm{Import}\left("example/address.ubj",\mathrm{base}=\mathrm{datadir}\right)$
 ${table}{}\left(\left[{"founded"}{=}{1988}{,}{"address"}{=}{table}{}\left(\left[{"streetAddress"}{=}{"615 Kumpf Drive"}{,}{"postalCode"}{=}{"N2V 1K8"}{,}{"city"}{=}{"Waterloo"}{,}{"province"}{=}{"ON"}{,}{"country"}{=}{"Canada"}\right]\right){,}{"companyName"}{=}{"Maplesoft"}{,}{"phoneNumbers"}{=}\left[{table}{}\left(\left[{"number"}{=}{"+1 \left(519\right) 747-2373"}{,}{"type"}{=}{"local"}\right]\right){,}{table}{}\left(\left[{"number"}{=}{"+1 \left(800\right) 267-6583"}{,}{"type"}{=}{"tollfree"}\right]\right){,}{table}{}\left(\left[{"number"}{=}{"+1 \left(519\right) 747-5284"}{,}{"type"}{=}{"fax"}\right]\right)\right]\right]\right)$ (3)

Export data to a UBJSON 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[{"Species"}{=}{"musculus"}{,}{"Genus"}{=}{"Mus"}\right]\right)$ (4)
 > $\mathrm{Mouse}\left["Family"\right]≔"Muridae"$
 ${{\mathrm{Mouse}}}_{{"Family"}}{≔}{"Muridae"}$ (5)
 > $\mathrm{Mouse}\left["Order"\right]≔"Rodentia"$
 ${{\mathrm{Mouse}}}_{{"Order"}}{≔}{"Rodentia"}$ (6)
 > $\mathrm{Mouse}\left["Class"\right]≔"Mammalia"$
 ${{\mathrm{Mouse}}}_{{"Class"}}{≔}{"Mammalia"}$ (7)
 > $\mathrm{Export}\left("mouse.ubj",\mathrm{Mouse},\mathrm{base}=\mathrm{homedir}\right)$
 ${81}$ (8)

 See Also