Struct Flattener

Source
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.

§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);
Source

pub fn new() -> Self

Returns a flattener with the default arguments

§Examples
use smooth_json;

let flattener = smooth_json::Flattener::new();
Source

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§

Source§

impl<'a> Default for Flattener<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.