serde_kson Macro
Kson is a Rust macro that simplifies the process of building and managing JSON-like data structures. It allows you to dynamically create and manipulate nested JSON objects and arrays using a simple syntax.
Features
- Easily create nested JSON structures
- Supports both object and array syntax
- Convenient access and update operations
Example Usage
Here's how you can use the kson! macro to build and interact with a JSON-like structure:
use serde_kson::kson;
fn main() {
kson!(a);
kson!(a["name"] = "kinggunil");
kson!(a["age"] = 40);
kson!(a["phone"]["office"] = "010-28**-3440");
kson!(a["phone"]["home"] = "031-7**-2440");
kson!(a["country"][0] = "Korea");
kson!(a["country"][1] = "Canada");
kson!(a["like"]["number"] = 777);
println!("Name: {:?}", kson!(a["name"] : String)); println!("Age next year: {:?}", kson!(a["age"] : i64) + 1); println!("Office phone: {:?}", kson!(a["phone"]["office"] : String)); println!("Home phone: {:?}", kson!(a["phone"]["home"] : String)); println!("First country: {:?}", kson!(a["country"][0] : String)); println!("Second country: {:?}", kson!(a["country"][1] : String)); println!("Favorite number: {:?}", kson!(a["like"]["number"] : i64)); }