// Example 41: JSON Serialization
// Demonstrates JSON handling with Windjammer's std.json abstraction
use std::json
@derive(Serialize, Deserialize, Debug, Clone)
struct User {
id: int,
name: string,
email: string,
}
fn main() {
println!("=== JSON Demo ===")
println!()
// 1. Serialize struct to JSON
println!("1. Serialize to JSON:")
let user = User {
id: 1,
name: "Alice",
email: "alice@example.com",
}
// Use Windjammer's json abstraction - no direct serde_json access!
match json.stringify(&user) {
Ok(json_compact) => {
println!(" Compact: {}", json_compact)
println!()
}
Err(e) => println!(" Error: {}", e)
}
// 2. Pretty-print JSON
println!("2. Pretty-print JSON:")
match json.pretty(&user) {
Ok(json_pretty) => {
println!("{}", json_pretty)
println!()
}
Err(e) => println!(" Error: {}", e)
}
println!("✨ JSON serialization with Windjammer!")
println!(" ✅ Using std.json abstraction (not serde_json directly)")
println!(" ✅ Dependencies added automatically")
println!(" ✅ Clean, Windjammer-native API")
}