#json

json-event-parser

A JSON event parser and serializer

2 releases

0.1.1 Jul 27, 2021
0.1.0 May 30, 2021

#131 in #json

Download history 35/week @ 2021-07-04 110/week @ 2021-07-11 105/week @ 2021-07-18 141/week @ 2021-07-25 67/week @ 2021-08-01 47/week @ 2021-08-08 247/week @ 2021-08-15 275/week @ 2021-08-22 81/week @ 2021-08-29 82/week @ 2021-09-05 81/week @ 2021-09-12 242/week @ 2021-09-19 101/week @ 2021-09-26 234/week @ 2021-10-03 67/week @ 2021-10-10 65/week @ 2021-10-17

137 downloads per month
Used in 4 crates (via oxigraph)

MIT/Apache

32KB
687 lines

JSON streaming parser

actions status Latest Version Released API docs

JSON event parser is a simple streaming JSON parser and serializer implementation in Rust.

It does not aims to be the fastest or the more versatile JSON parser possible but to be an as simple as possible implementation.

If you want fast and battle-tested code you might prefer to use json, serde_json or simd-json.

Reader example:

use json_event_parser::{JsonReader, JsonEvent};
use std::io::Cursor;

let json = b"{\"foo\": 1}";
let mut reader = JsonReader::from_reader(Cursor::new(json));

let mut buffer = Vec::new();
assert_eq!(JsonEvent::StartObject, reader.read_event(&mut buffer)?);
assert_eq!(JsonEvent::ObjectKey("foo"), reader.read_event(&mut buffer)?);
assert_eq!(JsonEvent::Number("1"), reader.read_event(&mut buffer)?);
assert_eq!(JsonEvent::EndObject, reader.read_event(&mut buffer)?);
assert_eq!(JsonEvent::Eof, reader.read_event(&mut buffer)?);

# std::io::Result::Ok(())

Writer example:

use json_event_parser::{JsonWriter, JsonEvent};

let mut buffer = Vec::new();
let mut writer = JsonWriter::from_writer(&mut buffer);
writer.write_event(JsonEvent::StartObject)?;
writer.write_event(JsonEvent::ObjectKey("foo"))?;
writer.write_event(JsonEvent::Number("1"))?;
writer.write_event(JsonEvent::EndObject)?;

assert_eq!(buffer.as_slice(), b"{\"foo\":1}");

# std::io::Result::Ok(())

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Futures by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Ya