Enum json::JsonValue [] [src]

pub enum JsonValue {
    String(String),
    Number(f64),
    Boolean(bool),
    Null,
    Object(BTreeMap<StringJsonValue>),
    Array(Vec<JsonValue>),
}

Variants

String(String)Number(f64)Boolean(bool)NullObject(BTreeMap<StringJsonValue>)Array(Vec<JsonValue>)

Methods

impl JsonValue
[src]

fn new_object() -> JsonValue

Create an empty JsonValue::Object instance. When creating an object with data, consider using the object! macro.

fn new_array() -> JsonValue

Create an empty JsonValue::Array instance. When creating array with data, consider using the array! macro.

fn is_string(&self) -> bool

fn is_number(&self) -> bool

fn is_boolean(&self) -> bool

fn is_null(&self) -> bool

fn is_object(&self) -> bool

fn is_array(&self) -> bool

fn is_empty(&self) -> bool

Checks whether the value is empty. Returns true for:

  • empty string ("")
  • number 0
  • boolean false
  • null
  • empty array (array![])
  • empty object (object!{})

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

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

fn as_f32(&self) -> Option<f32>

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

fn as_u32(&self) -> Option<u32>

fn as_u16(&self) -> Option<u16>

fn as_u8(&self) -> Option<u8>

fn as_usize(&self) -> Option<usize>

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

fn as_i32(&self) -> Option<i32>

fn as_i16(&self) -> Option<i16>

fn as_i8(&self) -> Option<i8>

fn as_isize(&self) -> Option<isize>

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

fn push<T>(&mut self, value: T) -> JsonResult<()> where T: Into<JsonValue>

Works on JsonValue::Array - pushes a new value to the array.

fn pop(&mut self) -> JsonValue

Works on JsonValue::Array - remove and return last element from an array. On failure returns a null.

fn contains<T>(&self, item: T) -> bool where T: Into<JsonValue>

Works on JsonValue::Array - checks if the array contains a value

fn len(&self) -> usize

Returns length of array or object (number of keys), defaults to 0 for other types.

fn members(&self) -> Members

Works on JsonValue::Array - returns an iterator over members.

fn members_mut(&mut self) -> MembersMut

Works on JsonValue::Array - returns a mutable iterator over members.

fn entries(&self) -> Entries

Works on JsonValue::Object - returns an iterator over key value pairs.

fn entries_mut(&mut self) -> EntriesMut

Works on JsonValue::Object - returns a mutable iterator over key value pairs.

fn remove(&mut self, key: &str) -> JsonValue

Works on JsonValue::Object - remove a key and return the value it held. If the key was not present, the method is called on anything but an object, it will return a null.

fn clear(&mut self)

When called on an array or an object, will wipe them clean. When called on a string will clear the string. Numbers and booleans become null.

impl JsonValue
[src]

fn dump(&self) -> String

Prints out the value as JSON string.

fn pretty(&self, spaces: u16) -> String

Pretty prints out the value as JSON string. Takes an argument that's number of spaces to indent new blocks with.

Trait Implementations

impl Clone for JsonValue
[src]

fn clone(&self) -> JsonValue

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl PartialEq for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, __arg_0: &JsonValue) -> bool

This method tests for !=.

impl Debug for JsonValue
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Index<usize> for JsonValue
[src]

Implements indexing by usize to easily access array members:

let mut array = JsonValue::new_array();

array.push("foo");

assert!(array[0] == "foo");

type Output = JsonValue

The returned type after indexing

fn index(&self, index: usize) -> &JsonValue

The method for the indexing (Foo[Bar]) operation

impl IndexMut<usize> for JsonValue
[src]

Implements mutable indexing by usize to easily modify array members:

let mut array = array!["foo", 3.14];

array[1] = "bar".into();

assert!(array[1] == "bar");

fn index_mut(&mut self, index: usize) -> &mut JsonValue

The method for the indexing (Foo[Bar]) operation

impl<'a> Index<&'a str> for JsonValue
[src]

Implements indexing by &str to easily access object members:

let object = object!{
    "foo" => "bar"
};

assert!(object["foo"] == "bar");

type Output = JsonValue

The returned type after indexing

fn index(&self, index: &str) -> &JsonValue

The method for the indexing (Foo[Bar]) operation

impl Index<String> for JsonValue
[src]

type Output = JsonValue

The returned type after indexing

fn index(&self, index: String) -> &JsonValue

The method for the indexing (Foo[Bar]) operation

impl<'a> Index<&'a String> for JsonValue
[src]

type Output = JsonValue

The returned type after indexing

fn index(&self, index: &String) -> &JsonValue

The method for the indexing (Foo[Bar]) operation

impl<'a> IndexMut<&'a str> for JsonValue
[src]

Implements mutable indexing by &str to easily modify object members:

let mut object = object!{};

object["foo"] = 42.into();

assert!(object["foo"] == 42);

fn index_mut(&mut self, index: &str) -> &mut JsonValue

The method for the indexing (Foo[Bar]) operation

impl IndexMut<String> for JsonValue
[src]

fn index_mut(&mut self, index: String) -> &mut JsonValue

The method for the indexing (Foo[Bar]) operation

impl<'a> IndexMut<&'a String> for JsonValue
[src]

fn index_mut(&mut self, index: &String) -> &mut JsonValue

The method for the indexing (Foo[Bar]) operation

impl Display for JsonValue
[src]

Implements formatting

let data = json::parse(r#"{"url":"https://github.com/"}"#).unwrap();
println!("{}", data);
println!("{:#}", data);

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

Formats the value using the given formatter.

impl<'a> From<&'a str> for JsonValue
[src]

fn from(val: &'a str) -> JsonValue

Performs the conversion.

impl<'a> From<Option<&'a str>> for JsonValue
[src]

fn from(val: Option<&'a str>) -> JsonValue

Performs the conversion.

impl From<HashMap<StringJsonValue>> for JsonValue
[src]

fn from(val: HashMap<StringJsonValue>) -> JsonValue

Performs the conversion.

impl From<Option<HashMap<StringJsonValue>>> for JsonValue
[src]

fn from(val: Option<HashMap<StringJsonValue>>) -> JsonValue

Performs the conversion.

impl From<Option<JsonValue>> for JsonValue
[src]

fn from(val: Option<JsonValue>) -> JsonValue

Performs the conversion.

impl<'a> PartialEq<&'a str> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl PartialEq<str> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<String> for JsonValue
[src]

fn from(val: String) -> JsonValue

Performs the conversion.

impl PartialEq<String> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<String> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<String>> for JsonValue
[src]

fn from(val: Option<String>) -> JsonValue

Performs the conversion.

impl From<Vec<String>> for JsonValue
[src]

fn from(val: Vec<String>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<String>>> for JsonValue
[src]

fn from(val: Vec<Option<String>>) -> JsonValue

Performs the conversion.

impl From<isize> for JsonValue
[src]

fn from(val: isize) -> JsonValue

Performs the conversion.

impl PartialEq<isize> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<isize> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<isize>> for JsonValue
[src]

fn from(val: Option<isize>) -> JsonValue

Performs the conversion.

impl From<Vec<isize>> for JsonValue
[src]

fn from(val: Vec<isize>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<isize>>> for JsonValue
[src]

fn from(val: Vec<Option<isize>>) -> JsonValue

Performs the conversion.

impl From<usize> for JsonValue
[src]

fn from(val: usize) -> JsonValue

Performs the conversion.

impl PartialEq<usize> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<usize> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<usize>> for JsonValue
[src]

fn from(val: Option<usize>) -> JsonValue

Performs the conversion.

impl From<Vec<usize>> for JsonValue
[src]

fn from(val: Vec<usize>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<usize>>> for JsonValue
[src]

fn from(val: Vec<Option<usize>>) -> JsonValue

Performs the conversion.

impl From<i8> for JsonValue
[src]

fn from(val: i8) -> JsonValue

Performs the conversion.

impl PartialEq<i8> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<i8> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<i8>> for JsonValue
[src]

fn from(val: Option<i8>) -> JsonValue

Performs the conversion.

impl From<Vec<i8>> for JsonValue
[src]

fn from(val: Vec<i8>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<i8>>> for JsonValue
[src]

fn from(val: Vec<Option<i8>>) -> JsonValue

Performs the conversion.

impl From<i16> for JsonValue
[src]

fn from(val: i16) -> JsonValue

Performs the conversion.

impl PartialEq<i16> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<i16> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<i16>> for JsonValue
[src]

fn from(val: Option<i16>) -> JsonValue

Performs the conversion.

impl From<Vec<i16>> for JsonValue
[src]

fn from(val: Vec<i16>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<i16>>> for JsonValue
[src]

fn from(val: Vec<Option<i16>>) -> JsonValue

Performs the conversion.

impl From<i32> for JsonValue
[src]

fn from(val: i32) -> JsonValue

Performs the conversion.

impl PartialEq<i32> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<i32> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<i32>> for JsonValue
[src]

fn from(val: Option<i32>) -> JsonValue

Performs the conversion.

impl From<Vec<i32>> for JsonValue
[src]

fn from(val: Vec<i32>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<i32>>> for JsonValue
[src]

fn from(val: Vec<Option<i32>>) -> JsonValue

Performs the conversion.

impl From<i64> for JsonValue
[src]

fn from(val: i64) -> JsonValue

Performs the conversion.

impl PartialEq<i64> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<i64> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<i64>> for JsonValue
[src]

fn from(val: Option<i64>) -> JsonValue

Performs the conversion.

impl From<Vec<i64>> for JsonValue
[src]

fn from(val: Vec<i64>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<i64>>> for JsonValue
[src]

fn from(val: Vec<Option<i64>>) -> JsonValue

Performs the conversion.

impl From<u8> for JsonValue
[src]

fn from(val: u8) -> JsonValue

Performs the conversion.

impl PartialEq<u8> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<u8> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<u8>> for JsonValue
[src]

fn from(val: Option<u8>) -> JsonValue

Performs the conversion.

impl From<Vec<u8>> for JsonValue
[src]

fn from(val: Vec<u8>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<u8>>> for JsonValue
[src]

fn from(val: Vec<Option<u8>>) -> JsonValue

Performs the conversion.

impl From<u16> for JsonValue
[src]

fn from(val: u16) -> JsonValue

Performs the conversion.

impl PartialEq<u16> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<u16> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<u16>> for JsonValue
[src]

fn from(val: Option<u16>) -> JsonValue

Performs the conversion.

impl From<Vec<u16>> for JsonValue
[src]

fn from(val: Vec<u16>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<u16>>> for JsonValue
[src]

fn from(val: Vec<Option<u16>>) -> JsonValue

Performs the conversion.

impl From<u32> for JsonValue
[src]

fn from(val: u32) -> JsonValue

Performs the conversion.

impl PartialEq<u32> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<u32> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<u32>> for JsonValue
[src]

fn from(val: Option<u32>) -> JsonValue

Performs the conversion.

impl From<Vec<u32>> for JsonValue
[src]

fn from(val: Vec<u32>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<u32>>> for JsonValue
[src]

fn from(val: Vec<Option<u32>>) -> JsonValue

Performs the conversion.

impl From<u64> for JsonValue
[src]

fn from(val: u64) -> JsonValue

Performs the conversion.

impl PartialEq<u64> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<u64> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<u64>> for JsonValue
[src]

fn from(val: Option<u64>) -> JsonValue

Performs the conversion.

impl From<Vec<u64>> for JsonValue
[src]

fn from(val: Vec<u64>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<u64>>> for JsonValue
[src]

fn from(val: Vec<Option<u64>>) -> JsonValue

Performs the conversion.

impl From<f32> for JsonValue
[src]

fn from(val: f32) -> JsonValue

Performs the conversion.

impl PartialEq<f32> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<f32> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<f32>> for JsonValue
[src]

fn from(val: Option<f32>) -> JsonValue

Performs the conversion.

impl From<Vec<f32>> for JsonValue
[src]

fn from(val: Vec<f32>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<f32>>> for JsonValue
[src]

fn from(val: Vec<Option<f32>>) -> JsonValue

Performs the conversion.

impl From<f64> for JsonValue
[src]

fn from(val: f64) -> JsonValue

Performs the conversion.

impl PartialEq<f64> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<f64> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<f64>> for JsonValue
[src]

fn from(val: Option<f64>) -> JsonValue

Performs the conversion.

impl From<Vec<f64>> for JsonValue
[src]

fn from(val: Vec<f64>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<f64>>> for JsonValue
[src]

fn from(val: Vec<Option<f64>>) -> JsonValue

Performs the conversion.

impl From<Object> for JsonValue
[src]

fn from(val: Object) -> JsonValue

Performs the conversion.

impl PartialEq<Object> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<Object> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<Object>> for JsonValue
[src]

fn from(val: Option<Object>) -> JsonValue

Performs the conversion.

impl From<Vec<Object>> for JsonValue
[src]

fn from(val: Vec<Object>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<Object>>> for JsonValue
[src]

fn from(val: Vec<Option<Object>>) -> JsonValue

Performs the conversion.

impl From<Array> for JsonValue
[src]

fn from(val: Array) -> JsonValue

Performs the conversion.

impl PartialEq<Array> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<Array> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<Array>> for JsonValue
[src]

fn from(val: Option<Array>) -> JsonValue

Performs the conversion.

impl From<Vec<Array>> for JsonValue
[src]

fn from(val: Vec<Array>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<Array>>> for JsonValue
[src]

fn from(val: Vec<Option<Array>>) -> JsonValue

Performs the conversion.

impl From<bool> for JsonValue
[src]

fn from(val: bool) -> JsonValue

Performs the conversion.

impl PartialEq<bool> for JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl<'a> PartialEq<bool> for &'a JsonValue
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl From<Option<bool>> for JsonValue
[src]

fn from(val: Option<bool>) -> JsonValue

Performs the conversion.

impl From<Vec<bool>> for JsonValue
[src]

fn from(val: Vec<bool>) -> JsonValue

Performs the conversion.

impl From<Vec<Option<bool>>> for JsonValue
[src]

fn from(val: Vec<Option<bool>>) -> JsonValue

Performs the conversion.