home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Read/Load A JSON File In Rust

August 2023
Code
[dependencies]
serde = { version = "1.0.105", features = ["derive"] }
serde_json = { version = "1.0.105" }
Code
use serde::Deserialize;
use std::fs;

#[derive(Deserialize, Debug)]
struct Widget {
    key: String,
}

fn main() {
    let data = fs::read_to_string("example.json").unwrap();
    let w: Widget = serde_json::from_str(data.as_str()).unwrap();
    dbg!(w);
}
Code
{
  "key": "alfa"
}

Notes

═══ § ═══

Footnotes And References