#json #serialization #events #json-event

json-event-parser

A JSON event parser and serializer

7 releases

0.2.2 Mar 8, 2025
0.2.1 Feb 23, 2025
0.2.0 Mar 23, 2024
0.2.0-alpha.2 Nov 13, 2023
0.1.0 May 30, 2021

#190 in Encoding

Download history 1201/week @ 2025-02-01 1452/week @ 2025-02-08 1276/week @ 2025-02-15 1852/week @ 2025-02-22 1317/week @ 2025-03-01 1675/week @ 2025-03-08 1251/week @ 2025-03-15 1510/week @ 2025-03-22 998/week @ 2025-03-29 905/week @ 2025-04-05 945/week @ 2025-04-12 850/week @ 2025-04-19 1069/week @ 2025-04-26 1260/week @ 2025-05-03 1902/week @ 2025-05-10 1422/week @ 2025-05-17

5,784 downloads per month
Used in 56 crates (6 directly)

MIT/Apache

67KB
1.5K SLoC

JSON streaming parser and serializer

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 JSON parser possible but to be a simple implementation allowing to parse larger than memory files.

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

Parser example:

use json_event_parser::{ReaderJsonParser, JsonEvent};

let json = b"{\"foo\": 1}";
let mut reader = ReaderJsonParser::new(json.as_slice());
assert_eq!(reader.parse_next()?, JsonEvent::StartObject);
assert_eq!(reader.parse_next()?, JsonEvent::ObjectKey("foo".into()));
assert_eq!(reader.parse_next()?, JsonEvent::Number("1".into()));
assert_eq!(reader.parse_next()?, JsonEvent::EndObject);
assert_eq!(reader.parse_next()?, JsonEvent::Eof);
# std::io::Result::Ok(())

Serializer example:

use json_event_parser::{WriterJsonSerializer, JsonEvent};

let mut writer = WriterJsonSerializer::new(Vec::new());
writer.write_event(JsonEvent::StartObject) ?;
writer.write_event(JsonEvent::ObjectKey("foo".into())) ?;
writer.write_event(JsonEvent::Number("1".into())) ?;
writer.write_event(JsonEvent::EndObject) ?;

assert_eq!(writer.finish()?.as_slice(), b"{\"foo\":1}");
# std::io::Result::Ok(())

License

This project is licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or <http://www.apache.org/licenses/LICENSE-2.0>)
  • MIT license (LICENSE-MIT or <http://opensource.org/licenses/MIT>)

at your option.

Contribution

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

Dependencies

~0–5.5MB
~19K SLoC