torvyn_cli/output/
json.rs1use serde::Serialize;
6
7pub fn print_json<T: Serialize>(value: &T) {
11 match serde_json::to_string_pretty(value) {
12 Ok(json_str) => {
13 println!("{json_str}");
14 }
15 Err(e) => {
16 eprintln!("error: Failed to serialize output to JSON: {e}");
17 println!(r#"{{"error": "serialization_failed", "detail": "{}"}}"#, e);
18 }
19 }
20}
21
22#[allow(dead_code)]
26pub fn print_ndjson<T: Serialize>(value: &T) {
27 match serde_json::to_string(value) {
28 Ok(json_str) => {
29 println!("{json_str}");
30 }
31 Err(e) => {
32 eprintln!("error: Failed to serialize event to JSON: {e}");
33 }
34 }
35}