Dup Ver Goto 📝

Json

PT2/lang/rust/data does not exist
To
27 lines, 77 words, 638 chars Page 'Json' does not exist.

Creating JSON

Use serde_json. But there are many other JSON crates. See docs for serde_json.

[dependencies]
...
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
...
use serde::{Serialize};
#[derive(Debug,Serialize)]
struct Flibble {
    hex: String,
    vision: String,
    potato: i32,
    people: f32
}

fn makejson1() {
    let data = Flibble { hex: String::from("Hex"), vision: String::from("Vision"), potato: 42, people: 3.14, };
    println!("{:?}",data);
    let json = serde_json::to_string(&data).unwrap();
    println!("{}",json);
}