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).
Serde is a tool that automatically converts your Rust data structures into formats like JSON or back again. You just add a small tag to your struct definition, and Serde writes the complex code needed to read and write that data for you. Think of it as a translator that instantly converts your internal Rust objects into a universal language other programs can understand.