Skip to main content

JsonTree

Struct JsonTree 

Source
pub struct JsonTree<'a> { /* private fields */ }
Expand description

A parsed value. The root is node 0.

Implementations§

Source§

impl<'a> JsonTree<'a>

Source

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.

Source

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.

Source

pub fn source(&self) -> &'a str

The whole text.

Source

pub fn into_nodes(self) -> Vec<JsonNode>

The nodes, for a caller that keeps them with its own copy of the text.

Source

pub fn node(&self, at: usize) -> &JsonNode

Source

pub fn item(&self, at: usize) -> &JsonItem

Source

pub fn text(&self, at: usize) -> &'a str

The text of a node in the input.

Source

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.

Source

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.

Source

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.

Source

pub fn type_name(&self, at: usize) -> &'static str

The type name of a node, as json_typeof and jsonb_typeof give it.

Source

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.

Source

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.

Source

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.

Source

pub fn compare(&self, other: &JsonTree<'_>) -> Ordering

compareJsonbContainers: the order of two jsonb values for the B-tree operators.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Debug for JsonTree<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for JsonTree<'a>

§

impl<'a> RefUnwindSafe for JsonTree<'a>

§

impl<'a> Send for JsonTree<'a>

§

impl<'a> Sync for JsonTree<'a>

§

impl<'a> Unpin for JsonTree<'a>

§

impl<'a> UnsafeUnpin for JsonTree<'a>

§

impl<'a> UnwindSafe for JsonTree<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.