c12-parser 1.1.0

Toolbox for parsing and stringifying various formats, including JSON, JSON5, JSONC, INI, TOML, and YAML.
Documentation
//! Example: parse TOML and stringify with outer whitespace preserved.

use c12_parser::{parse_toml, stringify_toml};
use toml::Value;

fn main() {
    let text = r#"

[package]
name = "c12-parser"
version = "1.0.0"

[dependencies]
serde = "1.0"
"#;

    let formatted = parse_toml::<Value>(text, None).expect("parse");
    if let Some(Value::Table(deps)) = formatted.value.get("dependencies") {
        println!("Dependencies: {:?}", deps.keys().collect::<Vec<_>>());
    }
    if let Some(Value::Table(pkg)) = formatted.value.get("package") {
        println!(
            "Package: {} {}",
            pkg.get("name").and_then(|v| v.as_str()).unwrap_or(""),
            pkg.get("version").and_then(|v| v.as_str()).unwrap_or("")
        );
    }

    let out = stringify_toml(&formatted, None).expect("stringify");
    println!("Stringify (outer whitespace preserved):\n{}", out);
}