feat(wpcarro/rust): Show 2/3 json examples
Documented in the module Change-Id: I550c233c8116904a1f9cd6841ee778eb0abb540a Reviewed-on: https://cl.tvl.fyi/c/depot/+/5897 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
This commit is contained in:
parent
8e9bfaba47
commit
c18ca0f852
1 changed files with 19 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
use serde_json::json;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
// From the serde_json docs:
|
||||
//
|
||||
|
@ -32,6 +32,22 @@ fn one() {
|
|||
println!("result: {:?}", data);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
one()
|
||||
// 2) Parse into a loosely typed representation; mutate it; serialize it back.
|
||||
// TL;DR:
|
||||
// - read: serde_json::from_str(data)
|
||||
// - write: x.to_string()
|
||||
fn two() {
|
||||
let data = r#"{"fname":"William","lname":"Carroll","age":30}"#;
|
||||
|
||||
let mut parsed: Value = serde_json::from_str(data).unwrap();
|
||||
parsed["fname"] = json!("Norm");
|
||||
parsed["lname"] = json!("Macdonald");
|
||||
parsed["age"] = json!(61);
|
||||
|
||||
let result = parsed.to_string();
|
||||
println!("result: {:?}", result);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
two()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue