UBJSON (.ubj)

Background

    MIME type: application/ubjson.
    Data interchange binary format.
    Supports full UBJSON syntax.
    UBJSON identifies UBJSON objects with Wolfram Language associations.
    UBJSON is an acronym derived from Universal Binary JSON.
    Binary format with big-endian order for numeric values.
    There is a one-to-one transformation between JSON and UBJSON.
    UBJSON is specified at http://ubjson.org/.

Import and Export

  • Import["file.ubj"] imports a UBJSON file as a combination of nested lists and associations.
  • ImportString["string","UBJSON"] imports a UBJSON string of bytes.
  • Export["file",expr,"UBJSON"] exports a combination of nested lists and associations to a UBJSON file.
  • ExportString[expr,"UBJSON"] exports to a UBJSON string of bytes.
  • The "UBJSON" format identifies UBJSON objects with associations in the Wolfram Language.
  • "UBJSON" identifies UBJSON lists [e1,e2,] with Wolfram Language lists {e1,e2,}.
  • Single-character strings in the Wolfram Language are represented in UBJSON as characters. Multi-character strings in the Wolfram Language are represented as UBJSON strings.
  • Machine-precision integers are represented as the smallest UBJSON integer type they fit in.
  • Big integers are represented as a UBJSON string of digits.
  • Machine-precision numbers in the Wolfram Language are represented by the smallest compatible UBJSON float type.
  • Wolfram Language packed arrays are represented as UBJSON arrays. Complex-number values are not supported.

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

Options

  • Export options:
  • "ConversionFunction"Nonefunction to apply for additional conversions
    "ConversionRules"{}rules to apply to override or add conversions
  • The setting for "ConversionRules" is used to replace subexpressions before built-in conversions are performed.
  • The setting for "ConversionFunction" is applied to subexpressions for which no built-in conversion is defined.

Examples

Basic Examples  (7)

Export a List to the UBJSON format:

In[1]:=
Click for copyable input

Import as an expression:

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

Export an Association to the UBJSON format:

In[1]:=
Click for copyable input

Import as an expression:

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

Exporting an integer produces an output of variable size:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=

Exporting a big integer produces an output of size proportional to the number of digits:

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

Exporting a ByteArray produces a compact, strongly typed, UBJSON array output:

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

Export the same data as a regular List:

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

Exporting a string of one ASCII character produces a UBJSON character:

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

Exporting non-ASCII characters produces a UBJSON string output:

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

Exporting a string produces a UBJSON string:

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

Use conversion rules to transform quantities to associations:

In[1]:=
Click for copyable input

Import as an expression:

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

See Also

"RawJSON"  "ExpressionJSON"  "JSON"  "HDF5"  "MX"  BinarySerialize  BinaryDeserialize

Introduced in 2017
(11.1)