Actson is a reactive JSON parser (sometimes referred to as non-blocking or asynchronous). It is event-based and can be used in asynchronous code (for example in combination with Tokio).
```rust use actson::{JsonParser, JsonEvent}; use actson::feeder::{DefaultJsonFeeder, JsonFeeder};
let json = r#"{"name": "Elvis"}"#.as_bytes();
let mut feeder = DefaultJsonFeeder::new(); let mut parser = JsonParser::new(); let mut i: usize = 0; loop { // feed as many bytes as possible to the parser let mut event = parser.nextevent(&mut feeder); while matches!(event, JsonEvent::NeedMoreInput) { i += feeder.feedbytes(&json[i..]); if i == json.len() { feeder.done(); } event = parser.next_event(&mut feeder); }
// do something useful with `event`
if matches!(event, JsonEvent::Error) {
// do proper error handling here!
panic!("Error while parsing JSON");
}
if matches!(event, JsonEvent::Eof) {
break;
}
} ```
Besides this implementation in Rust here, there is a Java implementation.
The event-based parser code and the JSON files used for testing are largely based on the file JSON_checker.c and the JSON test suite from JSON.org originally released under this license (basically MIT license).
Actson is released under the MIT license. See the LICENSE file for more information.