Expand description
§rill-json
rill-json is a fast, 100% safe, and RFC 8259-compliant streaming JSON parser
and serializer, built from scratch in pure Rust.
This library is designed for performance, safety, and correctness.
§Key Features
- 100% Safe Rust: Contains no
unsafecode. - Streaming Parser: An
Iteratorthat emitsParserEvents, ideal for parsing large files with minimal memory. - Optimized Performance: Uses a byte-slice-based tokenizer with a
branchless Lookup Table (LUT) and
memchrfor high-performance, safe-SIMD-accelerated string parsing. - Serializer Included: Comes with
stringify()andstringify_pretty()to serialize your Rust data back to JSON. - RFC 8259 Compliant: Passes a full test suite for specification compliance.
§Quick Start: Parsing (Streaming)
The parse_streaming function is the primary entry point. It’s the most
efficient way to parse JSON, especially large files.
no_run use rill_json::{parse_streaming, ParserEvent};
fn main() { let json_data = r#“{ “name”: “Babbage”, “id”: 1815 }“#; let mut parser = parse_streaming(json_data).unwrap(); let mut found_name_key = false;
while let Some(event) = parser.next() {
match event.unwrap() {
ParserEvent::Key(key) if key == "name" => found_name_key = true,
ParserEvent::String(value) if found_name_key => {
println!("Found name: {}", value);
break;
}
_ => found_name_key = false,
}
}}
// ## Quick Start: Serializing
// You can also create JSON strings from your own Rust data using the `JsonValue` enum.
```no_run
use rill_json::JsonValue;
use std::collections::HashMap;
let mut user = HashMap::new();
user.insert("username".to_string(), JsonValue::String("ada_l".to_string()));
user.insert("id".to_string(), JsonValue::Number(1815.0));
let json_object = JsonValue::Object(user);
// Get the compact string
let json_string = json_object.stringify();
assert_eq!(json_string, r#"{"id":1815,"username":"ada_l"}"#);Re-exports§
pub use error::ParseError;pub use parser::ParserEvent;pub use parser::StreamingParser;pub use value::JsonValue;
Modules§
- error
- Contains the primary
ParseErrortype for the library. Contains the primaryParseErrortype for the library. - parser
- Contains the streaming
Parserand itsParserEventenum. Contains theStreamingParserand its state machine. - token
- Contains the
TokenandTokenTypeenums used internally. Defines theTokenandTokenTypeenums. - value
- Contains the
JsonValueenum and the serialization (stringify) logic. Contains theJsonValueenum, a native Rust representation of any valid JSON value.
Functions§
- parse_
streaming - Parses a JSON string slice into a
StreamingParser.