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 possibleStreamParser- Parses JSON from anyReadersource, 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§
- Array
BitBucket - Array-based BitBucket implementation for large storage capacity.
- BitStack
Struct - BitStack configuration for custom bit depth parsing.
- Chunk
Reader - A
Readerthat reads from a byte slice, optionally in fixed-size chunks. - Default
Config - Default depth configuration using u32 for tracking bits and u8 for counting depth.
- Push
Parser - A SAX-style JSON push parser.
- Slice
Parser - A pull parser that parses JSON from a slice.
- Stream
Parser - A pull parser that parses JSON from a stream.
Enums§
- Event
- Events produced by JSON parsers
- Json
Number - Represents a JSON number with both exact string representation and parsed value.
- Number
Result - Represents the parsed result of a JSON number.
- Parse
Error - Errors that can occur during JSON parsing
- Push
Parse Error - An error that can occur during push-based 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.
- BitStack
Config - Configuration trait for BitStack systems - defines bucket and counter types.
- Depth
Counter - Trait for depth counters - tracks nesting depth.
- Pull
Parser - Trait for parsers that can be used in a pull-based manner.
- Push
Parser Handler - A trait for handling events from a SAX-style push parser.
- Reader
- Trait for input sources that can provide data to the streaming parser.
Type Aliases§
- Array
BitStack - Array-based BitStack implementation for large storage capacity.