pub enum JsonValue {
Null,
Bool(bool),
Number(f64),
Str(String),
Array(Vec<JsonValue>),
Object(Vec<(String, JsonValue)>),
}Expand description
A JSON value that covers all standard JSON types.
Variants§
Null
JSON null.
Bool(bool)
JSON boolean.
Number(f64)
JSON number (stored as f64).
Str(String)
JSON string.
Array(Vec<JsonValue>)
JSON array.
Object(Vec<(String, JsonValue)>)
JSON object as ordered key-value pairs.
Implementations§
Source§impl JsonValue
impl JsonValue
Sourcepub fn to_json_string(&self) -> String
pub fn to_json_string(&self) -> String
Serialize this value to a JSON string.
Sourcepub fn to_json_pretty(&self, indent: usize) -> String
pub fn to_json_pretty(&self, indent: usize) -> String
Serialize to a pretty-printed JSON string with indentation.
Sourcepub fn as_array(&self) -> Option<&Vec<JsonValue>>
pub fn as_array(&self) -> Option<&Vec<JsonValue>>
If this is an Array, return a reference to the inner Vec.
Sourcepub fn as_object(&self) -> Option<&Vec<(String, JsonValue)>>
pub fn as_object(&self) -> Option<&Vec<(String, JsonValue)>>
If this is an Object, return a reference to the inner pairs.
Sourcepub fn get(&self, key: &str) -> Option<&JsonValue>
pub fn get(&self, key: &str) -> Option<&JsonValue>
Look up a key in an Object. Returns None if not an object or key absent.
Sourcepub fn get_index(&self, i: usize) -> Option<&JsonValue>
pub fn get_index(&self, i: usize) -> Option<&JsonValue>
Index into an Array. Returns None if not an array or index out of bounds.
Sourcepub fn get_path(&self, path: &str) -> Option<&JsonValue>
pub fn get_path(&self, path: &str) -> Option<&JsonValue>
Navigate a dot-separated path like “a.b.c” through nested objects.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the number of elements in an array or object, or 0 otherwise.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return true if this value is an empty array, empty object, or null.
Trait Implementations§
impl StructuralPartialEq for JsonValue
Auto Trait Implementations§
impl Freeze for JsonValue
impl RefUnwindSafe for JsonValue
impl Send for JsonValue
impl Sync for JsonValue
impl Unpin for JsonValue
impl UnsafeUnpin for JsonValue
impl UnwindSafe for JsonValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.