Crate rill_json

Crate rill_json 

Source
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 unsafe code.
  • Streaming Parser: An Iterator that emits ParserEvents, ideal for parsing large files with minimal memory.
  • Optimized Performance: Uses a byte-slice-based tokenizer with a branchless Lookup Table (LUT) and memchr for high-performance, safe-SIMD-accelerated string parsing.
  • Serializer Included: Comes with stringify() and stringify_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 ParseError type for the library. Contains the primary ParseError type for the library.
parser
Contains the streaming Parser and its ParserEvent enum. Contains the StreamingParser and its state machine.
token
Contains the Token and TokenType enums used internally. Defines the Token and TokenType enums.
value
Contains the JsonValue enum and the serialization (stringify) logic. Contains the JsonValue enum, a native Rust representation of any valid JSON value.

Functions§

parse_streaming
Parses a JSON string slice into a StreamingParser.