|
1 |
| -JSON streaming parser |
2 |
| -================= |
| 1 | +JSON streaming parser and serializer |
| 2 | +==================================== |
3 | 3 |
|
4 | 4 | [](https://github.com/oxigraph/json-event-parser/actions)
|
5 | 5 | [](https://crates.io/crates/json-event-parser)
|
6 | 6 | [](https://docs.rs/json-event-parser)
|
7 | 7 |
|
8 | 8 | JSON event parser is a simple streaming JSON parser and serializer implementation in Rust.
|
9 | 9 |
|
10 |
| -It does not aims to be the fastest JSON parser possible but to be a simple implementation. |
| 10 | +It does not aims to be the fastest JSON parser possible but to be a simple implementation allowing to parse larger than |
| 11 | +memory files. |
11 | 12 |
|
12 |
| -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). |
| 13 | +If you want fast and battle-tested code you might prefer to |
| 14 | +use [json](https://crates.io/crates/json), [serde_json](https://crates.io/crates/serde_json) |
| 15 | +or [simd-json](https://crates.io/crates/simd-json). |
13 | 16 |
|
14 |
| -Reader example: |
| 17 | +Parser example: |
15 | 18 |
|
16 | 19 | ```rust
|
17 |
| -use json_event_parser::{FromReadJsonReader, JsonEvent}; |
| 20 | +use json_event_parser::{ReaderJsonParser, JsonEvent}; |
18 | 21 |
|
19 | 22 | let json = b"{\"foo\": 1}";
|
20 |
| -let mut reader = FromReadJsonReader::new(json.as_slice()); |
21 |
| -assert_eq!(reader.read_next_event()?, JsonEvent::StartObject); |
22 |
| -assert_eq!(reader.read_next_event()?, JsonEvent::ObjectKey("foo".into())); |
23 |
| -assert_eq!(reader.read_next_event()?, JsonEvent::Number("1".into())); |
24 |
| -assert_eq!(reader.read_next_event()?, JsonEvent::EndObject); |
25 |
| -assert_eq!(reader.read_next_event()?, JsonEvent::Eof); |
| 23 | +let mut reader = ReaderJsonParser::new(json.as_slice()); |
| 24 | +assert_eq!(reader.parse_next()?, JsonEvent::StartObject); |
| 25 | +assert_eq!(reader.parse_next()?, JsonEvent::ObjectKey("foo".into())); |
| 26 | +assert_eq!(reader.parse_next()?, JsonEvent::Number("1".into())); |
| 27 | +assert_eq!(reader.parse_next()?, JsonEvent::EndObject); |
| 28 | +assert_eq!(reader.parse_next()?, JsonEvent::Eof); |
26 | 29 | # std::io::Result::Ok(())
|
27 | 30 | ```
|
28 | 31 |
|
29 |
| -Writer example: |
| 32 | +Serializer example: |
30 | 33 |
|
31 | 34 | ```rust
|
32 |
| -use json_event_parser::{ToWriteJsonWriter, JsonEvent}; |
| 35 | +use json_event_parser::{WriterJsonSerializer, JsonEvent}; |
33 | 36 |
|
34 |
| -let mut writer = ToWriteJsonWriter::new(Vec::new()); |
35 |
| -writer.write_event(JsonEvent::StartObject)?; |
36 |
| -writer.write_event(JsonEvent::ObjectKey("foo".into()))?; |
37 |
| -writer.write_event(JsonEvent::Number("1".into()))?; |
38 |
| -writer.write_event(JsonEvent::EndObject)?; |
| 37 | +let mut writer = WriterJsonSerializer::new(Vec::new()); |
| 38 | +writer.write_event(JsonEvent::StartObject) ?; |
| 39 | +writer.write_event(JsonEvent::ObjectKey("foo".into())) ?; |
| 40 | +writer.write_event(JsonEvent::Number("1".into())) ?; |
| 41 | +writer.write_event(JsonEvent::EndObject) ?; |
39 | 42 |
|
40 | 43 | assert_eq!(writer.finish()?.as_slice(), b"{\"foo\":1}");
|
41 | 44 | # std::io::Result::Ok(())
|
42 | 45 | ```
|
43 | 46 |
|
44 |
| - |
45 | 47 | ## License
|
46 | 48 |
|
47 | 49 | This project is licensed under either of
|
48 | 50 |
|
49 |
| - * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or |
50 |
| - `<http://www.apache.org/licenses/LICENSE-2.0>`) |
51 |
| - * MIT license ([LICENSE-MIT](LICENSE-MIT) or |
52 |
| - `<http://opensource.org/licenses/MIT>`) |
53 |
| - |
54 |
| -at your option. |
| 51 | +* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or |
| 52 | + `<http://www.apache.org/licenses/LICENSE-2.0>`) |
| 53 | +* MIT license ([LICENSE-MIT](LICENSE-MIT) or |
| 54 | + `<http://opensource.org/licenses/MIT>`) |
55 | 55 |
|
| 56 | +at your option. |
56 | 57 |
|
57 | 58 | ### Contribution
|
58 | 59 |
|
59 |
| -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. |
| 60 | +Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in json-event-parser by |
| 61 | +you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. |
0 commit comments