请输入您要查询的百科知识:

 

词条 UBJSON
释义

  1. Rationale and Objectives

  2. Data types and syntax

     Value types  type  length (optional)  data (optional)  Container types 

  3. Representation

  4. See also

  5. External links

{{unreferenced|date=March 2014}}{{Infobox software
| name = UBJSON
| author = The Buzz Media, LLC
| genre = Data interchange
| license = Apache 2.0
| programming language = Various languages
| operating_system = Any
| platform = Cross-platform
| status = Active
| latest_release_version = Draft 12
| website = {{URL|http://ubjson.org/}}
}}

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.

Rationale and Objectives

UBJSON is a proposed successor to BSON, BJSON and others. UBJSON has the following goals:

  • Complete compatibility with the JSON specification – there is a 1:1 mapping between standard JSON and UBJSON.
  • Ease of implementation – only including data types that are widely supported in popular programming languages so that there are no problems with certain languages not being supported well.
  • Ease of use – it can be quickly understood and adopted.
  • Speed and efficiency – UBJSON uses data representations that are (roughly) 30% smaller than their compacted JSON counterparts and are optimized for fast parsing. Streamed serialisation is supported, meaning that the transfer of UBJSON over a network connection can start sending data before the final size of the data is known.

Data types and syntax

UBJSON data can be either a value or a container.

Value types

UBJSON uses a single binary tuple to represent all JSON value types:

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. There is also a no-op type used for stream keep-alive.

  • Null: Z
  • No-op: N - no operation, to be ignored by the receiving end
  • Boolean types: true (T) and false (F)
  • Numeric types: int8 (i), uint8 (U), int16 (I), int32 (l), int64 (L), float32 (d), float64 (D), and high-precision (H)
  • ASCII character: C
  • UTF-8 string: S

High-precision numbers are represented as an arbitrarily long, UTF-8 string-encoded numeric value.

length (optional)

The length is an integer number (int8, uint8, int16, int32 or int64) encoding the size of the data payload in bytes. It is used for strings, high-precision numbers and optionally containers. They are omitted for other types.

Length is encoded following the same convention as integers, thus including its own type. For example, the string hello is encoded as S,U,0x05,h,e,l,l,o.

data (optional)

A sequence of bytes representing the actual binary data for this type of value. All numbers are in big-endian order.

Container types

Similarly to JSON, UBJSON defines two container types: array and object.

Arrays are ordered sequences of elements, represented as a [ followed by zero or more elements of value and container type and a trailing ].

Objects are labeled sets of elements, represented as a { followed by zero or more key-value pairs and a trailing }. Each key is a string with the S character omitted, and each "value" can be any element of value or container type.

Alternatively, arrays and objects may indicate the number of elements they contain as # followed by an integer number before their first element, in which case the trailing ] or } is omitted. Additionally, if all elements have the same type, the types can be omitted and replaced by a single $ followed by the type, in which case the element count must follow immediately. For example, the array ["a","b","c"] may be represented as [,$,C,#,U,0x03,a,b,c.

Representation

The MIME type 'application/ubjson' is recommended, as is the file extension '.ubj' when stored in a file-system.

See also

  • JSON
  • BSON
  • Protocol Buffers
  • Apache Thrift
  • MessagePack

External links

  • {{Official website}}

1 : Data serialization formats

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/17 20:01:51