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 theJSON
standard and can be used to store complex data structures. - Fast performance:
jsonb
is designed for high performance, allowing you to work with largeJSON
data sets with ease. - Easy to use:
jsonb
provides a number of built-in functions to support various operations, and also supports theJSONPath
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
andarray
, and 29 bits identify the number of JEntries in thearray
orobject
. The root node of thejsonb
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
andcontainer
, 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 header0x50000000
- 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 nestedjson
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§
Structs§
- Owned
Jsonb - Represents a JSONB data that owns its underlying data.
- RawJsonb
- Represents JSONB data wrapped around a raw, immutable slice of bytes.
Enums§
Functions§
- from_
raw_ jsonb - Deserializes a
RawJsonb
into a Rust data structure using Serde. - from_
slice - The binary
JSONB
contains three parts,Header
,JEntry
andRawData
. This structure can be nested. Each group of structures starts with aHeader
. The upper-levelValue
will store theHeader
length or offset of the lower-levelValue
. - parse_
value - to_
owned_ jsonb - Serializes a Rust data structure into an
OwnedJsonb
using Serde.