Rust: Parse nested JSON

Rust: Parse nested JSON

Not a whole lot new to cover here that isn’t already implied from the previous parsing JSON lesson. It works exactly as you’d expect. So here’s a bonus shorthand way to parse an object into a JSON structure:

use serde_json::json;

fn main() {
 let glenn = json!({
        "name": "Glenn Gillen",
        "age": 40,
        "phones": [
            "+61 448612567"
        ],
        "address": {
            "line1": "123 Main St",
            "state": "VIC",
            "country": "AU"
        }
    });

    println!("first phone number: {}", glenn["phones"][0]);
    println!("state: {}", glenn["address"]["state"]);
    println!("{}", glenn.to_string());
}

Published: 24/03/2022

Hi, I'm Glenn! 👋

I've spent most of my career working with or at startups. I'm currently the VP of Product / GTM @ Ockam where I'm helping developers build applications and systems that are secure-by-design. It's time we started securely connecting apps, not networks.

Previously I led the Terraform product team @ HashiCorp, where we launched Terraform 1.0, Terraform Cloud, and a whole host of amazing capabilities that set the stage for a successful IPO. Prior to that I was part of the Startup Team @ AWS, and earlier still an early employee @ Heroku. I've also invested in a couple of dozen early stage startups.