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:
jsonbfully supports theJSONstandard and can be used to store complex data structures. - Fast performance:
jsonbis designed for high performance, allowing you to work with largeJSONdata sets with ease. - Easy to use:
jsonbprovides a number of built-in functions to support various operations, and also supports theJSONPathsyntax for selecting and extracting subset elements. - Safe and secure:
jsonbis 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,objectandarray, and 29 bits identify the number of JEntries in thearrayorobject. The root node of thejsonbvalue is always a container header.scalarcontainer header:0x20000000objectcontainer header:0x40000000arraycontainer 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,trueandcontainer, and the remaining 28 bits identify the length or offset of the encoding value.nullJEntry header:0x00000000stringJEntry header:0x10000000numberJEntry header:0x20000000falseJEntry header:0x30000000trueJEntry header:0x40000000containerJEntry 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 nestedjsonvalue 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§
- Date
- Represents a calendar date (year, month, day) without time component.
- Decimal64
- Represents a decimal number with 64-bit precision.
- Decimal128
- Represents a decimal number with 128-bit precision.
- Decimal256
- Represents a decimal number with 256-bit precision.
- Interval
- Represents a time interval or duration.
- Owned
Jsonb - Represents a JSONB data that owns its underlying data.
- RawJsonb
- Represents JSONB data wrapped around a raw, immutable slice of bytes.
- Timestamp
- Represents a timestamp (date and time) without timezone information.
- Timestamp
Tz - Represents a timestamp with timezone information.
Enums§
- Error
- Extension
Value - Represents extended JSON value types that are not supported in standard JSON.
- Number
- Represents a JSON number with multiple possible internal representations.
- Value
- Represents a JSON or extended JSON value.
Functions§
- from_
raw_ jsonb - Deserializes a
RawJsonbinto a Rust data structure using Serde. - from_
slice - The binary
JSONBcontains three parts,Header,JEntryandRawData. This structure can be nested. Each group of structures starts with aHeader. The upper-levelValuewill store theHeaderlength or offset of the lower-levelValue. - parse_
owned_ jsonb - Parses JSON text into an owned JSONB binary representation. The parser will follow extended JSON syntax rules.
- parse_
owned_ jsonb_ standard_ mode - Parses JSON text into an owned JSONB binary representation using standard JSON syntax rules. The parser will follow standard JSON syntax rules.
- parse_
owned_ jsonb_ standard_ mode_ with_ buf - Parses JSON text into a provided buffer as JSONB binary representation using standard JSON syntax rules. The parser will follow standard JSON syntax rules.
- parse_
owned_ jsonb_ with_ buf - Parses JSON text into a provided buffer as JSONB binary representation. The parser will follow extended JSON syntax rules.
- parse_
value - Parse JSON text to JSONB Value with extended mode. The parser will follow extended JSON syntax rules like leading plus signs, multiple leading zeros, decimal points without digits, and empty array elements. Numeric values are preferentially parsed as decimal values to ensure that precision is not lost.
- parse_
value_ standard_ mode - Parse JSON text to JSONB Value with standard mode. The parser will follow standard JSON syntax rules.
- to_
owned_ jsonb - Serializes a Rust data structure into an
OwnedJsonbusing Serde.