You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`jsonb` is a jsonb implementation written in Rust. It provides a fast, lightweight, and easy-to-use API for working with jsonb data.
10
+
`jsonb` is a binary format `JSON` representation inspired by [PostgreSQL](https://www.postgresql.org/docs/current/datatype-json.html) and [CockroachDB](https://www.cockroachlabs.com/docs/stable/jsonb). It provides a fast, lightweight and easy-to-use API for working with `JSON` data.
12
11
13
12
## Features
14
13
15
-
- Fast performance: `jsonb` is designed to be highly performant, allowing you to work with large jsonb data sets with ease.
16
-
- Easy to use API: `jsonb` provides a simple and intuitive API for working with jsonb data, making it easy to get started.
17
-
- Safe and secure: `jsonb` is written in Rust, which provides memory safety and thread safety guarantees, making it a safe choice for handling sensitive data.
18
-
- Flexible: `jsonb` supports a wide range of data types and can be used to store complex data structures.
14
+
- Good compatibility: `jsonb` fully supports the `JSON` standard and can be used to store complex data structures.
15
+
- Fast performance: `jsonb` is designed for high performance, allowing you to work with large `JSON` data sets with ease.
16
+
- 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.
17
+
- Safe and secure: `jsonb` is written in Rust, which provides memory and thread safety guarantees, making it a safe choice for handling sensitive data.
18
+
19
+
## Encoding format
20
+
21
+
The `jsonb` encoding format is a tree-like structure. Each node contains a container header, a number of JEntry headers, and nested encoding values.
22
+
23
+
- 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.
24
+
-`scalar` container header: `0x20000000`
25
+
-`object` container header: `0x40000000`
26
+
-`array` container header: `0x80000000`
27
+
- 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.
28
+
-`null` JEntry header: `0x00000000`
29
+
-`string` JEntry header: `0x10000000`
30
+
-`number` JEntry header: `0x20000000`
31
+
-`false` JEntry header: `0x30000000`
32
+
-`true` JEntry header: `0x40000000`
33
+
-`container` JEntry header `0x50000000`
34
+
- Encoding value. Different types of JEntry header have different encoding values.
35
+
-`null`, `true`, `false`: no encoding value, identified by the JEntry header.
36
+
-`string`: a normal UTF-8 string.
37
+
-`number`: an encoded number to represent uint64s, int64s and float64s.
38
+
-`container`: a nested `json` value with a recursive structure.
19
39
40
+
#### An encoding example
41
+
42
+
```text
43
+
// JSON value
44
+
[false, 10, {"k":"v"}]
45
+
46
+
// JSONB encoding
47
+
0x80000003 array container header (3 JEntries)
48
+
0x30000000 false JEntry header (no encoding value)
49
+
0x20000002 number JEntry header (encoding value length 2)
50
+
0x5000000e container JEntry header (encoding value length 14)
51
+
0x500a number encoding value (10)
52
+
0x40000001 object container header (1 JEntry)
53
+
0x10000001 string key JEntry header (encoding value length 1)
54
+
0x10000001 string value JEntry header (encoding value length 1)
55
+
0x6b string encoding value ("k")
56
+
0x76 string encoding value ("v")
57
+
```
20
58
21
-
## JSONB value struct
59
+
## Jsonb value
22
60
23
-
```rust
24
-
// JSONB value
61
+
The `jsonb` value is an enumeration that represents all kinds of `JSON` values and serves as an intermediate for converting other data types to the `jsonb` binary format value.
62
+
63
+
```rust
64
+
// jsonb value
25
65
#[derive(Clone, PartialEq, Eq)]
26
66
pubenumValue<'a> {
27
67
Null,
@@ -33,3 +73,73 @@ pub enum Value<'a> {
33
73
}
34
74
```
35
75
76
+
## Built-in functions
77
+
78
+
`jsonb` implements a number of commonly used built-in functions. Since most functions only focus on a subset of the total value, using container headers and JEntry headers to can efficiently skip over intermediate parts of the `jsonb` value. This avoids time-consuming deserialisation operations and provides very high performance. For more information, see https://docs.rs/jsonb/latest/jsonb/#functions
79
+
80
+
## SQL/JSONPath
81
+
82
+
[SQL/JSONPath](https://www.iso.org/standard/67367.html) is a query language used to select and extract a subset of elements from a `jsonb` value.
Copy file name to clipboardExpand all lines: src/lib.rs
+49Lines changed: 49 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,55 @@
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+
//! `jsonb` is a binary format `JSON` representation inspired by [PostgreSQL](https://www.postgresql.org/docs/current/datatype-json.html) and [CockroachDB](https://www.cockroachlabs.com/docs/stable/jsonb). It provides a fast, lightweight and easy-to-use API for working with `JSON` data.
16
+
//!
17
+
//! ## Features
18
+
//!
19
+
//! - Good compatibility: `jsonb` fully supports the `JSON` standard and can be used to store complex data structures.
20
+
//! - Fast performance: `jsonb` is designed for high performance, allowing you to work with large `JSON` data sets with ease.
21
+
//! - 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.
22
+
//! - Safe and secure: `jsonb` is written in Rust, which provides memory and thread safety guarantees, making it a safe choice for handling sensitive data.
23
+
//!
24
+
//! ## Encoding format
25
+
//!
26
+
//! The `jsonb` encoding format is a tree-like structure. Each node contains a container header, a number of JEntry headers, and nested encoding values.
27
+
//!
28
+
//! - 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.
29
+
//! - `scalar` container header: `0x20000000`
30
+
//! - `object` container header: `0x40000000`
31
+
//! - `array` container header: `0x80000000`
32
+
//! - 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.
33
+
//! - `null` JEntry header: `0x00000000`
34
+
//! - `string` JEntry header: `0x10000000`
35
+
//! - `number` JEntry header: `0x20000000`
36
+
//! - `false` JEntry header: `0x30000000`
37
+
//! - `true` JEntry header: `0x40000000`
38
+
//! - `container` JEntry header `0x50000000`
39
+
//! - Encoding value. Different types of JEntry header have different encoding values.
40
+
//! - `null`, `true`, `false`: no encoding value, identified by the JEntry header.
41
+
//! - `string`: a normal UTF-8 string.
42
+
//! - `number`: an encoded number to represent uint64s, int64s and float64s.
43
+
//! - `container`: a nested `json` value with a recursive structure.
0 commit comments