pub struct JsonTree<'a> { /* private fields */ }Expand description
A parsed value. The root is node 0.
Implementations§
Source§impl<'a> JsonTree<'a>
impl<'a> JsonTree<'a>
Sourcepub fn parse(text: &'a str) -> Result<JsonTree<'a>, TypeError>
pub fn parse(text: &'a str) -> Result<JsonTree<'a>, TypeError>
Parses the text of a json or a jsonb value. The lexer decodes the escapes, as makeJsonLexContext with need_escapes does, so a json value with \u0000 or a lone surrogate gives the error of jsonb_in.
§Errors
The error of the input of jsonb for the text.
Sourcepub fn parse_with(
text: &'a str,
escapes: bool,
) -> Result<JsonTree<'a>, TypeError>
pub fn parse_with( text: &'a str, escapes: bool, ) -> Result<JsonTree<'a>, TypeError>
Parses the text with the escapes decoded or not. Without the escapes, the text of a string node is not decoded and a json value always parses.
§Errors
The error of the input of json or jsonb for the text.
Sourcepub fn into_nodes(self) -> Vec<JsonNode>
pub fn into_nodes(self) -> Vec<JsonNode>
The nodes, for a caller that keeps them with its own copy of the text.
pub fn node(&self, at: usize) -> &JsonNode
pub fn item(&self, at: usize) -> &JsonItem
Sourcepub fn field(&self, at: usize, key: &str) -> Option<usize>
pub fn field(&self, at: usize, key: &str) -> Option<usize>
The value of the last field with the key key, when the node is an object.
Sourcepub fn element(&self, at: usize, index: i64) -> Option<usize>
pub fn element(&self, at: usize, index: i64) -> Option<usize>
The element at index, when the node is an array. A negative index counts from the end.
Sourcepub fn as_text(&self, at: usize) -> Option<String>
pub fn as_text(&self, at: usize) -> Option<String>
JsonbValueAsText and the text variants of get_worker: a string decoded, null as None, and the text of the node for the other kinds.
Sourcepub fn type_name(&self, at: usize) -> &'static str
pub fn type_name(&self, at: usize) -> &'static str
The type name of a node, as json_typeof and jsonb_typeof give it.
Sourcepub fn tokens(&self) -> Tokens<'_, 'a> ⓘ
pub fn tokens(&self) -> Tokens<'_, 'a> ⓘ
The tokens of the value in the order of JsonbIteratorNext. A scalar at the root is in an array with the raw mark, as jsonb keeps it.
Sourcepub fn strip_nulls(&self, arrays: bool, spaces: bool) -> String
pub fn strip_nulls(&self, arrays: bool, spaces: bool) -> String
The text of the value with the null fields of the objects removed and, with arrays, the null elements of the arrays removed. With spaces, there is one space after each comma and each colon, as jsonb prints. The strings and the keys have the escapes of escape_json, and the other scalars are their text in the input. This is json_strip_nulls and jsonb_strip_nulls.
Sourcepub fn pretty(&self) -> String
pub fn pretty(&self) -> String
JsonbToCStringIndent: the text of jsonb_pretty, with each element and each field on its own line and four spaces for each level.
Sourcepub fn compare(&self, other: &JsonTree<'_>) -> Ordering
pub fn compare(&self, other: &JsonTree<'_>) -> Ordering
compareJsonbContainers: the order of two jsonb values for the B-tree operators.
Sourcepub fn contains(&self, other: &JsonTree<'_>) -> Result<bool, TypeError>
pub fn contains(&self, other: &JsonTree<'_>) -> Result<bool, TypeError>
JsonbDeepContains: true when the value contains other, as the operator @> of jsonb finds.
§Errors
stack depth limit exceeded for a value with too many levels.
Sourcepub fn exists(&self, key: &str) -> bool
pub fn exists(&self, key: &str) -> bool
findJsonbValueFromContainer for a string: true when the value is an object with the key key, or an array with the string key as an element. A scalar at the root is an array.
Sourcepub fn set_path(
&self,
path: &[Option<&str>],
new: &str,
op: PathOp,
) -> Result<String, TypeError>
pub fn set_path( &self, path: &[Option<&str>], new: &str, op: PathOp, ) -> Result<String, TypeError>
setPath: the text of the value with the part at path replaced, created, deleted or inserted. new is the text of the new part, which PathOp::Delete does not use. The keys of a new field are not in their sorted place, so give the text to jsonb_in. The root must be an array or an object, and path must not be empty.
§Errors
A null element or an element that is not an integer in the path where the value has an array, cannot replace existing key for an insert into an object, and stack depth limit exceeded.