c12-parser
Installation
Add this crate by cargo
Usage
use ;
Contribution
- Clone this repository
- Install the latest version of Rust
- Run tests using
cargo testorcargo run
Add this crate by cargo
cargo add c12-parser
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"
}
"#;
// Parse JSON into a serde_json::Value
let value = parse_json(text)?;
// Mutate the config as needed
let mut obj = value.as_object().cloned().unwrap();
obj.insert("debug".into(), true.into());
// Control how formatting is preserved
let opts = FormatOptions {
indent: None, // auto-detect indent from original text
preserve_indentation: true, // keep original indentation where possible
preserve_whitespace: true, // keep leading/trailing whitespace
sample_size: 1024,
};
// Stringify back to JSON while preserving formatting
let output = stringify_json(&obj.into(), Some(&opts))?;
println!("{output}");
Ok(())
}
cargo test or cargo run