Crate jsonb

Source
Expand description

jsonb is a binary format JSON representation inspired by PostgreSQL and CockroachDB. It provides a fast, lightweight and easy-to-use API for working with JSON data.

§Features

  • Good compatibility: jsonb fully supports the JSON standard and can be used to store complex data structures.
  • Fast performance: jsonb is designed for high performance, allowing you to work with large JSON data sets with ease.
  • Easy to use: jsonb provides a number of built-in functions to support various operations, and also supports the JSONPath syntax for selecting and extracting subset elements.
  • Safe and secure: jsonb is written in Rust, which provides memory and thread safety guarantees, making it a safe choice for handling sensitive data.

§Encoding format

The jsonb encoding format is a tree-like structure. Each node contains a container header, a number of JEntry headers, and nested encoding values.

  • 32-bit container header. 3 bits identify the type of value, including scalar, object and array, and 29 bits identify the number of JEntries in the array or object. The root node of the jsonb value is always a container header.
    • scalar container header: 0x20000000
    • object container header: 0x40000000
    • array container header: 0x80000000
  • 32-bit JEntry header. 1 bit identifies whether the JEntry stores a length or an offset, 3 bits identify the type of value, including null, string, number, false, true and container, and the remaining 28 bits identify the length or offset of the encoding value.
    • null JEntry header: 0x00000000
    • string JEntry header: 0x10000000
    • number JEntry header: 0x20000000
    • false JEntry header: 0x30000000
    • true JEntry header: 0x40000000
    • container JEntry header 0x50000000
  • Encoding value. Different types of JEntry header have different encoding values.
    • null, true, false: no encoding value, identified by the JEntry header.
    • string: a normal UTF-8 string.
    • number: an encoded number to represent uint64s, int64s and float64s.
    • container: a nested json value with a recursive structure.
§An encoding example
// JSON value
[false, 10, {"k":"v"}]

// JSONB encoding
0x80000003    array container header (3 JEntries)
0x30000000    false JEntry header (no encoding value)
0x20000002    number JEntry header (encoding value length 2)
0x5000000e    container JEntry header (encoding value length 14)
0x500a        number encoding value (10)
0x40000001    object container header (1 JEntry)
0x10000001    string key JEntry header (encoding value length 1)
0x10000001    string value JEntry header (encoding value length 1)
0x6b          string encoding value ("k")
0x76          string encoding value ("v")

Modules§

core
jsonpath
keypath

Structs§

OwnedJsonb
Represents a JSONB data that owns its underlying data.
RawJsonb
Represents JSONB data wrapped around a raw, immutable slice of bytes.

Enums§

Error
Number
Value

Functions§

from_raw_jsonb
Deserializes a RawJsonb into a Rust data structure using Serde.
from_slice
The binary JSONB contains three parts, Header, JEntry and RawData. This structure can be nested. Each group of structures starts with a Header. The upper-level Value will store the Header length or offset of the lower-level Value.
parse_value
to_owned_jsonb
Serializes a Rust data structure into an OwnedJsonb using Serde.

Type Aliases§

Object