pub struct Flattener { /* private fields */ }
Expand description
Basic struct of this crate. It contains the configuration. Instantiate it and use the method
flatten
to flatten a JSON object.
Implementations§
Source§impl Flattener
impl Flattener
Sourcepub fn set_key_separator(self, key_separator: &str) -> Self
pub fn set_key_separator(self, key_separator: &str) -> Self
Changes the string used to separate keys in the resulting flattened object.
Sourcepub fn set_array_formatting(self, array_formatting: ArrayFormatting) -> Self
pub fn set_array_formatting(self, array_formatting: ArrayFormatting) -> Self
Changes the way arrays are formatted. By default the position in the array is treated as a normal key, but with this function we can change this behaviour.
Sourcepub fn set_preserve_empty_arrays(self, value: bool) -> Self
pub fn set_preserve_empty_arrays(self, value: bool) -> Self
Changes the behaviour regarding empty arrays []
Sourcepub fn set_preserve_empty_objects(self, value: bool) -> Self
pub fn set_preserve_empty_objects(self, value: bool) -> Self
Changes the behaviour regarding empty objects {}
pub fn key_separator(&self) -> &str
pub fn array_formatting(&self) -> &ArrayFormatting
pub fn preserve_empty_arrays(&self) -> bool
pub fn preserve_empty_objects(&self) -> bool
Sourcepub fn flatten(&self, to_flatten: &Value) -> Result<Value, Error>
pub fn flatten(&self, to_flatten: &Value) -> Result<Value, Error>
Flattens the provided JSON object (current
).
It will return an error if flattening the object would make two keys to be the same, overwriting a value. It will alre return an error if the JSON value passed it’s not an object.
§Errors
Will return Err
if to_flatten
it’s not an object, or if flattening the object would
result in two or more keys colliding.