Skip to main content

JsonValue

Enum JsonValue 

Source
pub enum JsonValue {
    Null,
    Bool(bool),
    Integer(i64),
    Float(f64),
    String(String),
    Array(Vec<JsonValue>),
    Object(Vec<(String, JsonValue)>),
}
Expand description

A dynamic JSON value

Variants§

§

Null

Null value

§

Bool(bool)

Boolean value

§

Integer(i64)

Integer value (fits in i64)

§

Float(f64)

Floating point value

§

String(String)

String value

§

Array(Vec<JsonValue>)

Array of values

§

Object(Vec<(String, JsonValue)>)

Object (key-value pairs)

Implementations§

Source§

impl JsonValue

Source

pub fn is_null(&self) -> bool

Check if value is null

Source

pub fn is_bool(&self) -> bool

Check if value is a boolean

Source

pub fn is_number(&self) -> bool

Check if value is a number (integer or float)

Source

pub fn is_integer(&self) -> bool

Check if value is an integer

Source

pub fn is_float(&self) -> bool

Check if value is a float

Source

pub fn is_string(&self) -> bool

Check if value is a string

Source

pub fn is_array(&self) -> bool

Check if value is an array

Source

pub fn is_object(&self) -> bool

Check if value is an object

Source

pub fn as_bool(&self) -> Option<bool>

Get as boolean

Source

pub fn as_i64(&self) -> Option<i64>

Get as i64

Source

pub fn as_u64(&self) -> Option<u64>

Get as u64

Source

pub fn as_f64(&self) -> Option<f64>

Get as f64

Source

pub fn as_str(&self) -> Option<&str>

Get as string slice

Source

pub fn as_array(&self) -> Option<&[JsonValue]>

Get as array slice

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<JsonValue>>

Get as mutable array

Source

pub fn as_object(&self) -> Option<&[(String, JsonValue)]>

Get as object slice

Source

pub fn as_object_mut(&mut self) -> Option<&mut Vec<(String, JsonValue)>>

Get as mutable object

Source

pub fn get(&self, key: &str) -> Option<&JsonValue>

Get a value from an object by key

Source

pub fn get_index(&self, index: usize) -> Option<&JsonValue>

Get a value from an array by index

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut JsonValue>

Get mutable reference to a value from an object by key

Source

pub fn into_string(self) -> Option<String>

Take ownership of a string value

Source

pub fn into_array(self) -> Option<Vec<JsonValue>>

Take ownership of an array value

Source

pub fn into_object(self) -> Option<Vec<(String, JsonValue)>>

Take ownership of an object value

Trait Implementations§

Source§

impl Clone for JsonValue

Source§

fn clone(&self) -> JsonValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JsonValue

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for JsonValue

Source§

fn default() -> JsonValue

Returns the “default value” for a type. Read more
Source§

impl From<&str> for JsonValue

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<JsonValue>> From<Option<T>> for JsonValue

Source§

fn from(v: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for JsonValue

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<JsonValue>> From<Vec<T>> for JsonValue

Source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for JsonValue

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for JsonValue

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for JsonValue

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for JsonValue

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for JsonValue

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for JsonValue

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for JsonValue

Source§

fn from(v: u64) -> Self

Converts to this type from the input type.
Source§

impl Index<&str> for JsonValue

Source§

type Output = JsonValue

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<usize> for JsonValue

Source§

type Output = JsonValue

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'de> JsonDeserialize<'de> for JsonValue

Source§

fn json_deserialize(parser: &mut JsonParser<'de>) -> Result<Self>

Deserialize a value from the given parser
Source§

impl JsonSerialize for JsonValue

Source§

fn json_serialize<W: Writer>(&self, writer: &mut JsonWriter<W>)

Serialize this value to the given writer
Source§

impl PartialEq for JsonValue

Source§

fn eq(&self, other: &JsonValue) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for JsonValue

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.