pub enum JsonText {
Null,
Bool(bool),
Number(String),
String(JsonString),
Array(Vec<JsonText>),
Object(Vec<(JsonString, JsonText)>),
Shared(Arc<JsonText>),
Link(Weak<JsonText>),
}Expand description
A JSON document read without replacing any text.
JsonText::Shared and JsonText::Link hold what JSON text cannot write: a value placed in
several parents, and a link back to a shared value that contains it, which makes a value that
contains itself. Neither is a node of its own: a walk counts each visit of the value it denotes,
as the TypeScript and Go runtimes do, so the node and nesting limits bound every walk. A link
must refer to a value that its owner holds; the parser never produces either variant.
Variants§
Null
null.
Bool(bool)
true or false.
Number(String)
A number, kept as written.
String(JsonString)
A string.
Array(Vec<JsonText>)
An array.
Object(Vec<(JsonString, JsonText)>)
An object with unique member names.
A value shared by several parents.
Link(Weak<JsonText>)
A link to a shared value, which makes a cycle when the link is inside that value.
Implementations§
Source§impl JsonText
impl JsonText
Sourcepub fn parse(text: &str) -> Result<JsonText, JsonTextError>
pub fn parse(text: &str) -> Result<JsonText, JsonTextError>
Read one JSON document with the grammar and nesting limit serde_json
applies, keeping every string as written.
Sourcepub fn get(&self, name: &str) -> Option<&JsonText>
pub fn get(&self, name: &str) -> Option<&JsonText>
The member name of an object. A shared object is read through its target; a link is not.
Sourcepub fn item(&self, index: usize) -> Option<&JsonText>
pub fn item(&self, index: usize) -> Option<&JsonText>
The item at index of an array. A shared array is read through its target; a link is not.
Sourcepub fn to_value(&self) -> Option<Value>
pub fn to_value(&self) -> Option<Value>
The value as Value, or None when it holds invalid text, a number
serde_json does not accept, or a value beyond its limits.
Sourcepub fn shape(&self) -> Value
pub fn shape(&self) -> Value
The document’s shape for request checks that read only kinds and valid
names: invalid text becomes an empty string, an invalid member name a
name no valid request member uses, and a number serde_json does not
accept null. A value beyond its limits has no shape and is null. The
shape is never an operation input; the text checks run before any part of
it reaches an operation.
Sourcepub fn has_invalid_text(&self) -> bool
pub fn has_invalid_text(&self) -> bool
Whether the first failure of the value is invalid text (see JsonText::invalid_path).
Sourcepub fn invalid_path(&self) -> Option<Vec<String>>
pub fn invalid_path(&self) -> Option<Vec<String>>
The path of the first failure when it is invalid text: the path of a string, or of the object whose member name is invalid. Members are visited in code point order of their names after every member name is checked, and array items in index order.
Sourcepub fn has_limit_violation(&self) -> bool
pub fn has_limit_violation(&self) -> bool
Whether this value holds a limit violation (too many nodes or too deep nesting).