Skip to main content

Crate jscan

Crate jscan 

Source
Expand description

High-performance zero-allocation JSON iterator and validator.

A faithful Rust port of romshark/jscan/v2.

§Example

use jscan::{scan, scan_str, ValueType};

// Works with &[u8]
let json = br#"{"name":"Alice","age":30}"#;
let err = scan(json, |iter| {
    println!("{}: {:?}", iter.pointer(), iter.value_type());
    false // continue scanning
});
assert!(err.is_none());

// Also works with &str via scan_str
let json = r#"{"name":"Alice","age":30}"#;
let err = scan_str(json, |iter| {
    if iter.value_type() == ValueType::Number {
        println!("{} = {}", iter.pointer(), iter.value_str());
    }
    false
});
assert!(err.is_none());

Structs§

Error
A JSON syntax error with location information.
Iterator
Provides access to the current JSON value during scanning.
Parser
Reusable parser. More efficient than the free functions for multiple inputs.
Validator
Reusable JSON validator. More efficient than the free functions when validating multiple inputs.

Enums§

ErrorCode
Error code identifying the type of JSON error.
ValueType
JSON value type.

Functions§

scan
Scan s as one complete JSON value, calling f for each encountered value. Returns None on success, or Some(Error) on failure.
scan_one
Scan one JSON value from the start of s, calling f for each encountered value. Returns (remaining, Option<Error>).
scan_str
Like scan, but accepts &str directly.
valid
Returns true if s is valid JSON.
valid_str
Like valid, but accepts &str directly.
validate
Validate that s is exactly one valid JSON value.
validate_one
Validate one JSON value from the start of s.
validate_str
Like validate, but accepts &str directly.