c12-parser

c12-parser is a parser for C12 configuration files, support JSON, JSON5, JSONC, YAML, TOML, INI.
Installation
Add this crate by cargo
cargo add c12-parser
Usage
use c12_parser::{
parse_json,
stringify_json,
FormatOptions,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = r#"
{
"name": "c12-parser",
"version": "1.0.0"
}
"#;
let value = parse_json(text)?;
let mut obj = value.as_object().cloned().unwrap();
obj.insert("debug".into(), true.into());
let opts = FormatOptions {
indent: None, preserve_indentation: true, preserve_whitespace: true, sample_size: 1024,
};
let output = stringify_json(&obj.into(), Some(&opts))?;
println!("{output}");
Ok(())
}
Contribution
- Clone this repository
- Install the latest version of Rust
- Run tests using
cargo test or cargo run
Credits
c12-loader has been inspired by several outstanding projects in the community:
- @confbox - Compact YAML, TOML, JSONC and JSON5 and INI parser and serializer
License
Published under the MIT license.
Made by @YONGQI 💛