Crate picojson

Source
Expand description

A minimal JSON pull-parser for resource-constrained environments.

picojson provides low-level, no_std compatible pull-parsers that operate without recursion or heap allocations, designed for embedded systems and memory-limited scenarios.

§Main Types

  • SliceParser - Parses JSON from byte slices or strings with zero-copy when possible
  • StreamParser - Parses JSON from any Reader source, buffering as needed

Both parsers emit Events representing JSON structure and values, allowing fine-grained control over parsing and memory usage.

§Quick Start

use picojson::{SliceParser, Event, String, PullParser};

let json = r#"{"name": "value"}"#;
let mut parser = SliceParser::new(json);

while let Some(event) = parser.next() {
    match event.expect("Parse error") {
        Event::Key(key) => println!("Found key: {}", key),
        _ => {}
    }
}

§String Escapes

For JSON containing escape sequences (like \n, \", \u0041), use constructors with scratch buffers to handle unescaping. The buffer must be at least as long as the longest contiguous string or number in your JSON:

let json = r#"{"msg": "Hello\nWorld"}"#;
let mut scratch = [0u8; 32];
let parser = SliceParser::with_buffer(json, &mut scratch);

§More Examples

For advanced usage including configurable nesting depth, number parsing options, and stream parsing, see the examples directory on GitHub.

Structs§

ArrayBitBucket
Array-based BitBucket implementation for large storage capacity.
BitStackStruct
BitStack configuration for custom bit depth parsing.
ChunkReader
A Reader that reads from a byte slice, optionally in fixed-size chunks.
DefaultConfig
Default depth configuration using u32 for tracking bits and u8 for counting depth.
SliceParser
A pull parser that parses JSON from a slice.
StreamParser
A pull parser that parses JSON from a stream.

Enums§

Event
Events produced by JSON parsers
JsonNumber
Represents a JSON number with both exact string representation and parsed value.
NumberResult
Represents the parsed result of a JSON number.
ParseError
Errors that can occur during JSON parsing
String
Represents a JSON string.

Traits§

BitBucket
Trait for bit buckets - provides bit storage for JSON parser state. This trait is implemented for both integer and [T; N] types.
BitStackConfig
Configuration trait for BitStack systems - defines bucket and counter types.
DepthCounter
Trait for depth counters - tracks nesting depth.
PullParser
Trait for parsers that can be used in a pull-based manner.
Reader
Trait for input sources that can provide data to the streaming parser.

Type Aliases§

ArrayBitStack
Array-based BitStack implementation for large storage capacity.