1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
JSON streaming parser and serializer
====================================
[](https://github.com/oxigraph/json-event-parser/actions)
[](https://crates.io/crates/json-event-parser)
[](https://docs.rs/json-event-parser)
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](https://crates.io/crates/json), [serde_json](https://crates.io/crates/serde_json)
or [simd-json](https://crates.io/crates/simd-json).
Parser example:
```rust
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:
```rust
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](LICENSE-APACHE) or
`<http://www.apache.org/licenses/LICENSE-2.0>`)
* MIT license ([LICENSE-MIT](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.
|