text_to_json/read/
to_json.rs1extern crate serde_json;
2
3use crate::*;
4use read::text;
5use serde_json::json;
6use std::io;
7
8pub fn to_json(file: String) -> io::Result<Vec::<String>> {
9 let txt = text(file).unwrap();
10 let res = spliting_text_by_space(txt).unwrap();
11 Ok(res)
12}
13
14fn spliting_text_by_space(text: String) -> io::Result<Vec::<String>> {
15 let space_char: &'static str = "\n";
16 let mut res = Vec::new();
17 for c in text.split(space_char) {
18 let get_char = spliting_text_by_key(c).unwrap();
19 res.push(get_char);
20 }
21 Ok(res)
22}
23
24fn spliting_text_by_key(text: &str) -> io::Result<String> {
25 let equal_char: &'static str = "=";
26 let mut res = Vec::new();
27 for c in text.split(equal_char) {
28 res.push(c);
29 }
30
31 let data_json = json!({
32 res[0]: res[1],
33 });
34
35 Ok(data_json.to_string())
36}