pub enum JsonValue {
Null,
Boolean(bool),
Number(f64),
String(String),
Array(Vec<JsonValue>),
Object(HashMap<String, JsonValue>),
}Expand description
A native Rust representation of any valid JSON value.
This enum is used by the stringify functions to serialize
Rust data into a JSON string.
Variants§
Null
Represents a JSON null.
Boolean(bool)
Represents a JSON true or false.
Number(f64)
Represents a JSON number (stored as f64).
String(String)
Represents a JSON string.
Array(Vec<JsonValue>)
Represents a JSON array (list).
Object(HashMap<String, JsonValue>)
Represents a JSON object (map).
Implementations§
Source§impl JsonValue
impl JsonValue
Sourcepub fn stringify(&self) -> String
pub fn stringify(&self) -> String
Serializes the JsonValue into a compact, minified JSON string.
§Examples
use rill_json::JsonValue;
let val = JsonValue::Number(123.0);
assert_eq!(val.stringify(), "123");Sourcepub fn stringify_pretty(&self) -> String
pub fn stringify_pretty(&self) -> String
Serializes the JsonValue into a human-readable,
indented JSON string (“pretty-print”).
§Examples
use rill_json::JsonValue;
use std::collections::HashMap;
let mut obj = HashMap::new();
obj.insert("key".to_string(), JsonValue::String("value".to_string()));
let val = JsonValue::Object(obj);
let pretty = val.stringify_pretty();
assert!(pretty.starts_with("{\n"));
assert!(pretty.contains("\n \"key\": \"value\"\n"));
assert!(pretty.ends_with("\n}"));Trait Implementations§
impl StructuralPartialEq for JsonValue
Auto Trait Implementations§
impl Freeze for JsonValue
impl RefUnwindSafe for JsonValue
impl Send for JsonValue
impl Sync for JsonValue
impl Unpin for JsonValue
impl UnwindSafe for JsonValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more