> For the complete documentation index, see [llms.txt](https://weerasak-chongnguluam.gitbook.io/sedoc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://weerasak-chongnguluam.gitbook.io/sedoc/rust/serde.md).

# Serde

### สร้าง JSON string จาก serde\_json::Value

ใน crate serde\_json จะมี type Value สำหรับ represent ข้อมูลแบบ JSON อยู่ นอกจากนั้นยังมี macro `json!` ที่ช่วยให้เราสร้าง Value ได้ง่ายๆและเอาไปแปลงเป็น JSON text ได้ง่ายๆด้วยตัวอย่างเช่น

```rust
use serde_json::json;

fn main() {
    let json_text = json!({
        "first_name": "John",
        "last_name": "Doe",
        "age": 34,
        "favorite_colors": ["red", "green", "blue"],
    });
    println!("{}", json_text.to_string());
}
```
