Read a JSON String into a Rust Struct with serde
Bring It In
This is how I'm pulling a string of JSON into a Rust struct:
---
serde =
serde_json = "1.0.140"
---
use Deserialize;
use serde_json;
Output:
[/Users/alan/.cargo/target/4b/0baba35be9214e/_active_nvim_run:32:5] data = Site {
title: "asdf",
pages: [
Page {
id: 12,
content: "quick fox",
},
Page {
id: 37,
content: "slow dog",
},
],
}
Notes
-
The
#![allow(dead_code)]
prevents a warning that shows up because this example doesn't really use the Site and Page struct. It wouldn't be necessary in practical code.
Super handy.
-a
-- end of line --