home ~ projects ~ socials

Get A Value Back Out Of Minijinja With Serde

These are just scratch notes showing something I got working. I'll make a better example as I have time. Also, I'm not sure if this is the most effificent way to do this, but it's the first thing I got to work

// not sure what all of this is needed
use minijinja::Value;
use neopoligengine::helpers::get_include_str_file;
use neopoligengine::section_v42::SectionV42;
use neopoligengine::{page_v42::PageV42, site_config::SiteConfigV42};
use serde::Deserialize;
//use serde::Deserializer;
use std::path::PathBuf;


/////

// this is whats in the function

        let v: serde_json::Value = serde_json::Value::deserialize(data).unwrap();
        let valid_tests = &v.as_object().unwrap()["tests"]["valid"]
            .as_array()
            .unwrap()
            .iter()
            .map(|obj| TestItem {
                description: obj["description"].as_str().unwrap().to_string(),
                source: obj["source"].as_str().unwrap().to_string(),
            })
            .collect::<Vec<TestItem>>();
-- end of line --