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<T>(&self, other: T) -> bool where T: Into<JsonValue>

Checks if the value stored matches other.

fn is_string(&self) -> bool

fn as_string(&self) -> JsonResult<&String>

fn is_number(&self) -> bool

fn as_number(&self) -> JsonResult<&f64>

fn is_boolean(&self) -> bool

fn as_boolean(&self) -> JsonResult<&bool>

fn is_null(&self) -> bool

fn is_object(&self) -> bool

fn is_array(&self) -> bool

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

Works on JsonValue::Object - create or override key with value.

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

Works on JsonValue::Object - get a reference to a value behind key. For most purposes consider using object[key] instead.

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

Works on JsonValue::Object - get a mutable reference to a value behind the key.

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

Attempts to get a mutable reference to the value behind a key on an object. If the reference doesn't exists, it will be created and assigned a null. If self is not an object, an empty object with null key will be created.

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

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

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

Works on JsonValue::Array - gets a reference to a value at index. For most purposes consider using array[index] instead.

fn at_mut(&mut self, index: usize) -> JsonResult<&mut JsonValue>

Works on JsonValue::Array - gets a mutable reference to a value at index.

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.

impl JsonValue
[src]

fn dump(&self) -> String

Prints out the value as JSON string.

fn pretty<'a>(&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 members of an array:

let mut array = JsonValue::new_array();

array.push("foo");

assert!(array[0].is("foo"));

type Output = JsonValue

The returned type after indexing

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

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

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

Implements indexing by &str to easily access object members:

let mut object = JsonValue::new_object();

object.put("foo", "bar");

assert!(object["foo"].is("bar"));

type Output = JsonValue

The returned type after indexing

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

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