Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.

un-rust/c12-parser

⚙️ c12-parser

Crates.io Version Crates.io Total Downloads docs.rs GitHub commit activity GitHub Repo stars

Toolbox for parsing and stringifying various formats, including JSON, JSON5, JSONC, INI, TOML, and YAML.

Full documentation →

Quick start

cargo add c12-parser

Usage

//! c12-parser API usage examples
//!
//! This binary demonstrates the main APIs. For full examples, see `examples/`:
//! - `cargo run --example hello_world`   — JSON parse & stringify
//! - `cargo run --example parse_json`    — JSON with FormatOptions
//! - `cargo run --example parse_json5`   — JSON5 (unquoted keys, trailing commas)
//! - `cargo run --example parse_jsonc`   — JSONC (comments, JsoncExtraOptions)
//! - `cargo run --example parse_toml`    — TOML
//! - `cargo run --example parse_yaml`    — YAML
//! - `cargo run --example parse_ini`     — INI

use c12_parser::{parse_ini, parse_json, parse_jsonc, stringify_ini, stringify_json, stringify_jsonc};
use serde_json::Value;

fn main() {
    println!("=== c12-parser API demo ===\n");

    // JSON: parse_json, stringify_json
    let json_text = r#"{ "name": "c12-parser", "version": "1.0" }"#;
    let formatted = parse_json::<Value>(json_text, None).expect("parse_json");
    let out = stringify_json(&formatted, None).expect("stringify_json");
    println!("JSON:  {} -> {:?}", json_text, out);

    // JSONC: parse_jsonc, stringify_jsonc (comments stripped)
    let jsonc_text = r#"{ /* comment */ "x": 1 }"#;
    let formatted = parse_jsonc(jsonc_text, None, None).expect("parse_jsonc");
    let out = stringify_jsonc(&formatted, None).expect("stringify_jsonc");
    println!("JSONC: {} -> {:?}", jsonc_text, out);

    // INI: parse_ini, stringify_ini
    let ini_text = r#"[section]
key = value"#;
    let map = parse_ini(ini_text);
    let out = stringify_ini(&map);
    println!("INI:   sections={:?} -> {}", map.keys().collect::<Vec<_>>(), out);

    println!("\nRun `cargo run --example <name>` for more examples.");
}

License

Published under the Apache-2.0 license. Made by @UnRUST 💛


🛠️ auto updated with automd-rs

About

⚙️ Toolbox for parsing and stringifying various formats, including JSON, JSON5, JSONC, INI, TOML, and YAML.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors

Generated from un-rust/template