json_to_yaml/
json_to_yaml.rs1use babbel_json::{FileDestination, FileSource, parse, to_yaml};
2use std::path::Path;
3
4#[path = "common/utility.rs"]
5mod json_utility_lib;
6use json_utility_lib::get_json_file_list;
7
8fn process_json_file(file_path: &str) -> Result<(), String> {
10 let mut source = FileSource::new(file_path).map_err(|e| e.to_string())?;
11 let node = parse(&mut source).map_err(|e| e.to_string())?;
12 let mut destination = FileDestination::new(
13 Path::new(file_path)
14 .with_extension("yaml")
15 .to_string_lossy()
16 .as_ref(),
17 )
18 .map_err(|e| e.to_string())?;
19
20 to_yaml(&node, &mut destination).map_err(|e| e.to_string())?;
21 Ok(())
22}
23
24fn main() {
25 let json_files = get_json_file_list("files");
26 for file_path in json_files {
27 match process_json_file(&file_path) {
28 Ok(()) => println!("Successfully converted {}", file_path),
29 Err(e) => eprintln!("Failed to convert {}: {}", file_path, e),
30 }
31 }
32}