pub struct JsonFile { /* private fields */ }
Expand description
A JSON File, stored in a “self-recursive” Map<u64, Value>
Note: If values are changed at some point, make sure that
Self::remove_null
is called after the changes have been
done: when a nested structure is removed, all contained
values are changed to Null; calling Self::remove_null
is
actually equivalent to a garbage collection process, in this
context.
Note: Object keys are stored in a [Pool
], which makes this
well suited for parsing large arrays of objects with similar
layouts.
Implementations§
source§impl JsonFile
impl JsonFile
sourcepub fn new(json: Option<&str>) -> Result<JsonFile, &'static str>
pub fn new(json: Option<&str>) -> Result<JsonFile, &'static str>
Creates a new JSON file (optionally from a JSON string)
sourcepub fn with_key_pool(
json: Option<&str>,
keys: Pool
) -> Result<JsonFile, &'static str>
pub fn with_key_pool( json: Option<&str>, keys: Pool ) -> Result<JsonFile, &'static str>
Creates a new JSON file using an existing key string pool (optionally from a JSON string)
pub fn get(&self, path: &Path) -> &Value
sourcepub fn remove_null(&mut self)
pub fn remove_null(&mut self)
Efficiently removes all Null values from the file.
Note: if a Null value was inserted in an array or an object, the key/index will persist, but the actual value will be removed.
sourcepub fn set_object(&mut self, path: &Path)
pub fn set_object(&mut self, path: &Path)
Create an object in the JSON file
sourcepub fn set_number(&mut self, path: &Path, value: f64)
pub fn set_number(&mut self, path: &Path, value: f64)
Insert a number in the JSON file
sourcepub fn set_string(&mut self, path: &Path, value: ArcStr)
pub fn set_string(&mut self, path: &Path, value: ArcStr)
Insert a string in the JSON file
sourcepub fn set_boolean(&mut self, path: &Path, value: bool)
pub fn set_boolean(&mut self, path: &Path, value: bool)
Insert a boolean in the JSON file
sourcepub fn push(&mut self, path: Path) -> Path
pub fn push(&mut self, path: Path) -> Path
Add an item to an array from the JSON file
The returned Path
leads to the new item.
Caution: this panics if the specified path leads to
a value which isn’t a Value::Array
sourcepub fn iter_array(&self, base_path: &Path) -> ArrayIter<'_>
pub fn iter_array(&self, base_path: &Path) -> ArrayIter<'_>
Iterates on the items in an array
Yields zero item if the value at base_path
is not an array.
sourcepub fn prop(&mut self, path: Path, key: &str) -> Path
pub fn prop(&mut self, path: Path, key: &str) -> Path
Add a property to an object from the JSON file
The returned Path
leads to the new property.
Has no effect no the file if the property already exists.
Caution: this panics if the specified path leads to
a value which isn’t a Value::Object