5 releases

0.2.0 Mar 23, 2024
0.2.0-alpha.2 Nov 13, 2023
0.2.0-alpha.1 Sep 23, 2023
0.1.1 Jul 27, 2021
0.1.0 May 30, 2021

#207 in Encoding

Download history 542/week @ 2024-04-03 443/week @ 2024-04-10 433/week @ 2024-04-17 535/week @ 2024-04-24 584/week @ 2024-05-01 338/week @ 2024-05-08 511/week @ 2024-05-15 590/week @ 2024-05-22 465/week @ 2024-05-29 578/week @ 2024-06-05 697/week @ 2024-06-12 550/week @ 2024-06-19 760/week @ 2024-06-26 512/week @ 2024-07-03 640/week @ 2024-07-10 589/week @ 2024-07-17

2,575 downloads per month
Used in 31 crates (5 directly)

MIT/Apache

63KB
1.5K SLoC

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 JSON parser possible but to be a simple 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::{FromReadJsonReader, JsonEvent};

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

Writer example:

use json_event_parser::{ToWriteJsonWriter, JsonEvent};

let mut writer = ToWriteJsonWriter::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–1.2MB
~20K SLoC