pub struct Flattener<'a> {
pub separator: &'a str,
pub alt_array_flattening: bool,
pub preserve_arrays: bool,
}
Expand description
Flattener is the main driver when flattening JSON
§Examples
use smooth_json;
let flattener = smooth_json::Flattener { ..Default::default() };
Fields§
§separator: &'a str
Alternate separator used between keys when flattening
§Examples
use smooth_json;
let flattener = smooth_json::Flattener { separator: "_", ..Default::default()};
alt_array_flattening: bool
Opinionated flattening format that places values in an array if the object is nested inside an array
§Examples
use smooth_json;
let flattener = smooth_json::Flattener { alt_array_flattening: true, ..Default::default()};
preserve_arrays: bool
Completely flatten JSON and keep array structure in the key when flattening
§Examples
use smooth_json;
let flattener = smooth_json::Flattener { preserve_arrays: true, ..Default::default()};
Implementations§
Source§impl<'a> Flattener<'a>
This implementation defines the core usage for the Flattener
structure.
impl<'a> Flattener<'a>
This implementation defines the core usage for the Flattener
structure.
§Examples
use smooth_json;
use serde_json::json;
let flattener = smooth_json::Flattener::new();
let example = json!({
"a": {
"b": "c"
}
});
let flattened_example = flattener.flatten(&example);
Sourcepub fn new() -> Self
pub fn new() -> Self
Returns a flattener with the default arguments
§Examples
use smooth_json;
let flattener = smooth_json::Flattener::new();
Sourcepub fn flatten(&self, json: &Value) -> Value
pub fn flatten(&self, json: &Value) -> Value
Flattens JSON variants into a JSON object
§Arguments
json
- A serde_json Value to flatten
§Examples
use smooth_json;
use serde_json::json;
let flattener = smooth_json::Flattener::new();
let example = json!({
"name": "John Doe",
"age": 43,
"address": {
"street": "10 Downing Street",
"city": "London"
},
"phones": [
"+44 1234567",
"+44 2345678"
]
});
let flattened_example = flattener.flatten(&example);
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Flattener<'a>
impl<'a> RefUnwindSafe for Flattener<'a>
impl<'a> Send for Flattener<'a>
impl<'a> Sync for Flattener<'a>
impl<'a> Unpin for Flattener<'a>
impl<'a> UnwindSafe for Flattener<'a>
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