Struct json_objects_to_csv::Json2Csv
source · [−]pub struct Json2Csv { /* private fields */ }
Expand description
Basic struct of this crate. It contains the configuration.Instantiate it and use the method
convert_from_array
or convert_from_file
to convert the JSON input into a CSV file.
Implementations
sourceimpl Json2Csv
impl Json2Csv
sourcepub fn new(flattener: Flattener) -> Self
pub fn new(flattener: Flattener) -> Self
Creates a JSON to CSV object with the flattening config provided.
sourcepub fn convert_from_array(
self,
objects: &[Value],
csv_writer: Writer<impl Write>
) -> Result<(), Error>
pub fn convert_from_array(
self,
objects: &[Value],
csv_writer: Writer<impl Write>
) -> Result<(), Error>
Flattens each one of the objects in the array slice and transforms each of them into a CSV row.
The headers of the CSV are the union of all the keys that result from flattening the objects in the input.
Errors
Will return Err
if objects
does not contain actual JSON objects. It will also report an
error if two objects have keys that should be different but end looking the same after
flattening, and if writing the CSV fails.
sourcepub fn convert_from_reader(
self,
reader: impl Read,
csv_writer: Writer<impl Write>
) -> Result<(), Error>
pub fn convert_from_reader(
self,
reader: impl Read,
csv_writer: Writer<impl Write>
) -> Result<(), Error>
Flattens the JSON objects in the file, transforming each of them into a CSV row.
The headers of the CSV are the union of all the keys that result from flattening the objects in the input. The file must contain JSON objects one immediately after the other or separated by whitespace. Note that it uses a temporary file to store the flattened input, which is automatically deleted when lo longer necessary.
Errors
Will return Err
if parsing the file fails or if the JSONs there are not objects. It will
also report an error if two objects have keys that should be different but end looking the
same after flattening, and if writing the CSV or to the temporary file fails.
Trait Implementations
impl Eq for Json2Csv
impl StructuralEq for Json2Csv
impl StructuralPartialEq for Json2Csv
Auto Trait Implementations
impl RefUnwindSafe for Json2Csv
impl Send for Json2Csv
impl Sync for Json2Csv
impl Unpin for Json2Csv
impl UnwindSafe for Json2Csv
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more