Original author(s) Development status Active Operating system | Stable release Draft 12 Written in Various languages Platform Cross-platform | |
Universal Binary JSON (UBJSON) is a computer data interchange format. It is a binary form directly imitating JSON, but requiring fewer bytes of data. It aims to achieve the generality of JSON, combined with being much easier to process than JSON.
Contents
Rationale and Objectives
UBJSON is a proposed successor to BSON, BJSON and others. UBJSON has the following goals:
Data types and syntax
UBJSON uses a single binary tuple to represent all JSON data types (both value and container types):
type [length] [data]Each element in the tuple is defined as:
type
The type is a 1-byte ASCII character used to indicate the type of the data following it. The ASCII characters were chosen to make manually walking and debugging data stored in the UBJSON format as easy as possible (e.g. making the data relatively readable in a hex editor). Types are available for the five JSON value types and the two JSON container types. There is also a no-op (used for stream keep-alive) and an end-of-container marker, used when a container of (as yet) unknown size had previously been started.
Huge numbers are represented as an arbitrarily long, UTF-8 string-encoded numeric value.
length (optional)
The length is a 1-byte or 4-byte value based on the type specified. These are used for strings, huge numbers and container/array blocks. They are omitted for other types.
The 1 and 4 byte lengths are easily differentiated because lower-case type characters are used in the 1-byte case, otherwise upper-case type characters are used.
data (optional)
A sequence of bytes representing the actual binary data for this type of value. All numbers are sent in big-endian order.
Representation
The MIME type 'application/ubjson' is recommended, as is the file extension '.ubj' when stored in a file-system.