Struct smooth_json::Flattener
source · pub struct Flattener<'a> {
pub separator: &'a str,
pub alt_array_flattening: bool,
}Expand description
Flattener is the main driver when flattening JSON
Fields§
§separator: &'a strAlternate separator used between keys when flattening
§Examples
use smooth_json;
let flattener = smooth_json::Flattener { separator: "_", ..Default::default()};alt_array_flattening: boolOpinionated 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()};Implementations§
source§impl<'a> Flattener<'a>
impl<'a> Flattener<'a>
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