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.
Implementation provides methods to construct and validate Json values.
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.
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.
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();
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.
Get a json field, within the document, locatable by path
.
Set a json field, within the document, locatable by path
.
Delete a json field, within the document, locatable by path
.
Append a string or array to a json field within the document that is
either a string or array.
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.
Implementation clones underlying type for each Json variant.
The return value is always an Option because JSON
follows a schemaless data representation.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
Returns the "default value" for a type. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Performs copy-assignment from source
. Read more
This method returns an Ordering
between self
and other
. Read more
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
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the +
operator.
Performs the +
operation.
The resulting type after applying the -
operator.
Performs the -
operation.
The resulting type after applying the *
operator.
Performs the *
operation.
The resulting type after applying the /
operator.
Performs the /
operation.
The resulting type after applying the %
operator.
Performs the %
operation.
The resulting type after applying the -
operator.
Performs the unary -
operation.
The resulting type after applying the !
operator.
Performs the unary !
operation.
The resulting type after applying the &
operator.
Performs the &
operation.
The resulting type after applying the |
operator.
Performs the |
operation.
The resulting type after applying the ^
operator.
Performs the ^
operation.
The resulting type after applying the <<
operator.
Performs the <<
operation.
The resulting type after applying the >>
operator.
Performs the >>
operation.
The returned type after indexing.
Performs the indexing (container[index]
) operation.
The returned type after indexing.
Performs the indexing (container[index]
) operation.
The associated error which can be returned from parsing.
Parses a string s
to return a value of this type. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String
. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static