[][src]Enum jsondata::Json

pub enum Json {
    Null,
    Bool(bool),
    Integer(Integral),
    Float(Floating),
    String(String),
    Array(Vec<Json>),
    Object(Vec<Property>),
    // some variants omitted
}

Json type implements JavaScript Object Notation as per specification RFC-8259.

  • Numbers are implemented with deferred conversion, using Integral and Floating types.
  • Arrays are implemented as vector of Json values Vec<Json>.
  • Objects are implemented as vector of properties, Vec<Property>, where each property is a tuple of (key, value). Here key is String type and value is Json type.

Variants

NullBool(bool)Integer(Integral)Float(Floating)String(String)Array(Vec<Json>)Object(Vec<Property>)

Methods

impl Json
[src]

Implementation provides methods to construct and validate Json values.

pub fn new<T>(value: T) -> Json where
    Self: From<T>, 
[src]

Construct Json from bool, i128, f64, String, str, Vec.

Array can be composed as:

use jsondata::Json;

let mut js = Json::new::<Vec<Json>>(Vec::new());
js.append("", Json::new(10));
js.append("", Json::new("hello world".to_string()));

It is also possbile to construct the vector of Json outside the append() method, and finally use Json::new() to construct the array.

Object can be composed as:

use jsondata::{Json, Property};

let mut js = Json::new::<Vec<Property>>(Vec::new());
js.set("/key1", Json::new(10));
js.set("/key2", Json::new(true));

It is also possbile to construct the vector of properties outside the set() method, and finally use Json::new() to construct the object.

pub fn validate(&mut self) -> Result<(), String>
[src]

Validate parts of JSON text that are not yet parsed. Typically, when used in database context, JSON documents are validated once but parsed multiple times.

pub fn compute(&mut self) -> Result<(), String>
[src]

Compute parses unparsed text and convert them into numbers. When a JSON document is parsed once but operated on multiple times it is better to call compute for better performance.

use jsondata::Json;

let text = r#"[null,true,false,10,"true"]"#;
let mut json: Json = text.parse().unwrap();
json.compute();

// perform lookup and arithmetic operations on parsed document.

impl Json
[src]

Implementation provides CRUD access into Json document using Json Pointer. For all methods,

  • Path must be valid JSON Pointer.
  • Path fragment must be valid key if parent container is an object.
  • Path fragment must be a number index if parent container is an array.

pub fn get(&self, path: &str) -> Result<Json, String>
[src]

Get a json field, within the document, locatable by path.

pub fn set(&mut self, path: &str, value: Json) -> Result<(), String>
[src]

Set a json field, within the document, locatable by path.

pub fn delete(&mut self, path: &str) -> Result<(), String>
[src]

Delete a json field, within the document, locatable by path.

pub fn append(&mut self, path: &str, value: Json) -> Result<(), String>
[src]

Append a string or array to a json field within the document that is either a string or array.

pub fn range<R>(&self, range: R) -> Json where
    R: RangeBounds<isize>, 
[src]

Range operation on Json array,

  • Range [start..end].
  • RangeFrom [start..].
  • RangeFull [..].
  • RangeInclusive [start..=end].
  • RangeTo [..end].
  • RangeToInclusive [..=end].

If range is called on non array Json, returns a Json Error.

impl Json
[src]

Implementation clones underlying type for each Json variant. The return value is always an Option because JSON follows a schemaless data representation.

pub fn boolean(&self) -> Option<bool>
[src]

pub fn integer(&self) -> Option<i128>
[src]

pub fn float(&self) -> Option<f64>
[src]

pub fn string(&self) -> Option<String>
[src]

pub fn array(&self) -> Option<Vec<Json>>
[src]

pub fn object(&self) -> Option<Vec<Property>>
[src]

pub fn is_error(&self) -> bool
[src]

pub fn error(&self) -> Option<String>
[src]

Trait Implementations

impl From<bool> for Json
[src]

impl From<i128> for Json
[src]

impl From<f64> for Json
[src]

impl From<String> for Json
[src]

impl<'_> From<&'_ str> for Json
[src]

impl From<Vec<Json>> for Json
[src]

impl From<Vec<Property>> for Json
[src]

impl From<Json> for bool
[src]

impl Eq for Json
[src]

impl PartialOrd<Json> for Json
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl AsMut<str> for Json
[src]

impl AsMut<Vec<Json>> for Json
[src]

impl AsMut<Vec<Property>> for Json
[src]

impl Default for Json
[src]

impl PartialEq<Json> for Json
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl AsRef<str> for Json
[src]

impl AsRef<Vec<Json>> for Json
[src]

impl AsRef<Vec<Property>> for Json
[src]

impl Clone for Json
[src]

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

Performs copy-assignment from source. Read more

impl Ord for Json
[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Debug for Json
[src]

impl Display for Json
[src]

impl Add<Json> for Json
[src]

type Output = Json

The resulting type after applying the + operator.

impl Sub<Json> for Json
[src]

type Output = Json

The resulting type after applying the - operator.

impl Mul<Json> for Json
[src]

type Output = Json

The resulting type after applying the * operator.

impl Div<Json> for Json
[src]

type Output = Json

The resulting type after applying the / operator.

impl Rem<Json> for Json
[src]

type Output = Json

The resulting type after applying the % operator.

impl Neg for Json
[src]

type Output = Json

The resulting type after applying the - operator.

impl Not for Json
[src]

type Output = Json

The resulting type after applying the ! operator.

impl BitAnd<Json> for Json
[src]

type Output = Json

The resulting type after applying the & operator.

impl BitOr<Json> for Json
[src]

type Output = Json

The resulting type after applying the | operator.

impl BitXor<Json> for Json
[src]

type Output = Json

The resulting type after applying the ^ operator.

impl Shl<Json> for Json
[src]

type Output = Json

The resulting type after applying the << operator.

impl Shr<Json> for Json
[src]

type Output = Json

The resulting type after applying the >> operator.

impl Index<isize> for Json
[src]

type Output = Json

The returned type after indexing.

impl<'_> Index<&'_ str> for Json
[src]

type Output = Json

The returned type after indexing.

impl FromStr for Json
[src]

type Err = String

The associated error which can be returned from parsing.

Auto Trait Implementations

impl Send for Json

impl Sync for Json

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]