How to Serialize and Deserialize Structs with Serde

Add the serde dependency and derive Serialize and Deserialize traits on your struct to handle JSON conversion.

Add the serde dependency with the derive feature to Cargo.toml, then use #[derive(serde::Serialize, serde::Deserialize)] on your struct to automatically generate the necessary code.

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
pub struct Config {
    output_mode: Mode,
}

To serialize a value to JSON, call serde_json::to_string(&value). To deserialize from JSON, call serde_json::from_str::<Config>(json_str).