flexon
A JSON parser with span tracking and optional comment support.
Example
For most use cases, all you need is the actual JSON data:
use parse;
let src = r#"{"blah": "was it really necessary?"}"#;
let val: & = parse.unwrap;
println!;
But wait, what about comments? For that you need to enable comment feature
use Parser;
let src = r#"
{
// A single-line comment
"nested": {
"one": "hello world"
}
/*
* A multi-line comment
*/
"mixed": [true, null, 1]
}
"#;
let parser = new;
let = parser.parse.unwrap;
let = comments.data;
println!;
assert!;
let = comments.data;
println!;
assert!;
// Index 11 falls within the single-line comment's range.
assert!;
// With the `line-count` feature enabled, you can find a comment by its line index.
// In that case, the parser returns `Metadata` instead of `Vec<..>`.
assert!;
Features
comment: Enable comment parsing. The performance overhead is significant.
line-count: Include line information and allow searching comments by line index. Performance overhead is somewhat minimal.
Performance
This was created solely for parsing JSONC with span support, so it has overhead than crates like serde-json or simd-json. If you compare this with them... you’ll see that they’re more than 2× faster, even with all the features disabled.
I can’t really justify thinking it’s slow just because of span support... but, but! This crate is also more than 2× faster than other crates that do similar thing, e.g. spanned-json-parser, jsonc-parser, or any other crates in general. Source? Trust me, bro.
Even though it can parse standard, strict JSON, you shouldn’t use it for that. Unless you need to parse JSON with comments or span support, don’t torture yourself and just use one of the faster crates mentioned earlier.