Input JSON Data
Rust Struct Code

Tool Instructions & Rust Struct Knowledge

Features

  • Serde Macro Support: Automatically generates #[derive(Serialize, Deserialize)] and #[serde(rename = "...")] attribute macros, which can be directly used with serde_json for serialization and deserialization.
  • Snake Case Conversion: Follows Rust's snake_case field naming conventions, automatically converting camelCase or other formats in JSON and generating the corresponding mappings.
  • Safe Option: Supports wrapping all field types in Option<T> to prevent panics caused by parsing failures when corresponding fields are missing in the JSON.
  • Smart Inference: Capable of distinguishing between i64 and f64 (floating-point numbers), automatically inferring Vec<T>, and intelligently filtering/evading Rust keywords (e.g., type converts to r#type).

Rust and JSON (Serde)

  • Serde Framework: The most famous serialization framework in the Rust ecosystem with extremely high performance. Typically, we need to add serde = { version = "1.0", features = ["derive"] } and serde_json = "1.0" to our `Cargo.toml`.
  • Ownership and References: The default type generated by the tool is String (which has ownership). This is the least likely to cause Lifetime issues during deserialization. For extremely high-performance scenarios, you can manually change String to &'a str, but you will need to handle the corresponding lifetime parameters.