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 62
#![warn(missing_docs)]
//! This crate implements a queryable, streaming, JSON pull parser.
//!
//! - __Pull parser?__: The parser is implemented as [an iterator](crate::Tokens) that emits
//! [tokens](crate::Token).
//! - __Streaming?__: The JSON document being parsed is never fully loaded into memory. It is read
//! & validated byte by byte. This makes it ideal for dealing with large JSON documents
//! - __Queryable?__ You can [configure the iterator](crate::Tokens::new) to only emit & allocate
//! tokens for the parts of the input you are interested in.
//!
//! JSON is expected to conform to [RFC
//! 8259](https://datatracker.ietf.org/doc/html/rfc8259).
//! It can come from any source that implements the [`Read`](std::io::Read) trait (e.g. a
//! file, byte slice, network socket etc..)
//!
//! ## Basic Usage
//!
//! ```
//! use jsn::{Tokens, select::*};
//!
//! let data = r#"
//!     {
//!         "name": "John Doe",
//!         "age": 43,
//!         "phones": [
//!             "+44 1234567",
//!             "+44 2345678",
//!         ]
//!     }
//! "#;
//!
//! let mut iter = Tokens::new(data.as_bytes(), key("age") | index(0));
//!
//! assert_eq!(iter.next().unwrap(), 43);
//! assert_eq!(iter.next().unwrap(), "+44 1234567");
//! assert_eq!(iter.next(), None);
//! ```
//!
//! A few things to notice and whet your appetite:
//! - The only JSON heap allocations are for the "age" and phone number tokens.
//! - You can compare tokens to native rust types directly
//! - Selectors match anywhere in json; Though the top-level value was an object, we used the
//! `index` selector to match a value that was at index 0 in an array nested in the "phones"
//! object.
mod error;
mod iter;
mod raw_token;
mod scan;
pub mod select;
mod stream;
mod token;
mod validate;
pub use error::{JsonError, Reason};
pub use iter::Tokens;
pub use token::{FromJson, Token};
#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDocTests;