How can an arbitrary json structure be deserialized with reqwest get in Rust?

You can use serde_json::Value.

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resp = reqwest::get("https://httpbin.org/ip")
        .await?
        .json::<serde_json::Value>()
        .await?;
    println!("{:#?}", resp);
    Ok(())
}

You will have to add serde_json to your Cargo.toml file.

[dependencies]
...
serde_json = "1"

Leave a Comment

tech