pub struct JsonFlattener<'a> {
pub separator: &'a str,
pub alt_array_flattening: bool,
pub preserve_arrays: bool,
}Expand description
JsonFlattener is the main driver when flattening JSON
§Examples
use nu_utils;
let flattener = nu_utils::JsonFlattener { ..Default::default() };Fields§
§separator: &'a strAlternate separator used between keys when flattening
§Examples
use nu_utils;
let flattener = nu_utils::JsonFlattener { 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 nu_utils;
let flattener = nu_utils::JsonFlattener { alt_array_flattening: true, ..Default::default()};preserve_arrays: boolCompletely flatten JSON and keep array structure in the key when flattening
§Examples
use nu_utils;
let flattener = nu_utils::JsonFlattener { preserve_arrays: true, ..Default::default()};Implementations§
Source§impl JsonFlattener<'_>
This implementation defines the core usage for the JsonFlattener structure.
impl JsonFlattener<'_>
This implementation defines the core usage for the JsonFlattener structure.
§Examples
use nu_utils;
use serde_json::json;
let flattener = nu_utils::JsonFlattener::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 nu_utils;
let flattener = nu_utils::JsonFlattener::new();Sourcepub fn flatten(&self, json: &SerdeValue) -> SerdeValue
pub fn flatten(&self, json: &SerdeValue) -> SerdeValue
Flattens JSON variants into a JSON object
§Arguments
json- A serde_json Value to flatten
§Examples
use nu_utils;
use serde_json::json;
let flattener = nu_utils::JsonFlattener::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 JsonFlattener<'a>
impl<'a> RefUnwindSafe for JsonFlattener<'a>
impl<'a> Send for JsonFlattener<'a>
impl<'a> Sync for JsonFlattener<'a>
impl<'a> Unpin for JsonFlattener<'a>
impl<'a> UnsafeUnpin for JsonFlattener<'a>
impl<'a> UnwindSafe for JsonFlattener<'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