Expand description
§JSON Fragment Scanner
A high-performance two-stage JSON fragment scanner that identifies and extracts JSON objects and arrays from complete documents using SIMD acceleration.
§Features
- Two-stage pipeline: Bulk character classification + fragment extraction
- SIMD-accelerated: AVX2/SSE4.2 for maximum throughput (5-10 GiB/s)
- Fragment detection: Identifies JSON objects (
{}) and arrays ([]) - Error reporting: Detailed error information for invalid fragments
- Position tracking: Absolute byte offsets for each fragment
- Nesting support: Handles arbitrary levels of nesting
§Quick Start
Extract the first JSON fragment from a string:
use json_extractor::extract_first;
let input = r#"some log prefix {"name": "Alice"} tail"#;
assert_eq!(extract_first(input), Some(r#"{"name": "Alice"}"#));§Advanced Usage
Use StagedScanner for repeated scans with buffer reuse:
use json_extractor::StagedScanner;
let mut scanner = StagedScanner::new();
let data = br#"{"name": "Alice"} {"age": 30}"#;
let fragments = scanner.scan_fragments(data);
assert_eq!(fragments.len(), 2);
assert!(fragments[0].is_complete());
assert_eq!(fragments[0].start, 0);Structs§
- Fragment
- Represents a found JSON fragment
- Json
Fragment Scanner - Convenience stateless API
- Staged
Scanner - Stateful JSON fragment scanner with buffer reuse
Enums§
- Error
Kind - Types of errors that can occur during parsing
- Fragment
Status - Fragment completion status
Functions§
- extract_
first - Extract the first complete JSON fragment from a string.