Skip to content

Instantly share code, notes, and snippets.

@sumeet
Created July 22, 2022 00:57
Show Gist options
  • Save sumeet/cf40e0c5b2f0f1dad61b767243e6cc86 to your computer and use it in GitHub Desktop.
Save sumeet/cf40e0c5b2f0f1dad61b767243e6cc86 to your computer and use it in GitHub Desktop.
use std::collections::HashMap;
use std::fs::read_to_string;
fn main() {
let filestr = read_to_string("example.csv").unwrap();
let mut lines = filestr.lines();
let header_row = lines.next().unwrap();
let field_names : Vec<_> = header_row.split(",").collect();
let objects : Vec<HashMap<_, _>> = lines.map(|line| {
let mut values = line.split(",");
field_names.iter().zip(values).collect()
}).collect();
println!("{}", serde_json::to_string_pretty(&objects).unwrap());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment