plainjson/
lib.rs

1//! This library simply provides:
2//! - JsonTag: A low-level JSON tag parser which reads JSON tags from an instance which implements trait std::io::Read
3//! - JsonNode: A JSON parser which supports getting or setting value from/to selected JSON nodes by JSONPath
4//!
5//! Note: Filter expression in JSONPath is not implemented yet, so currently filter expression is not supported.
6//!
7//! Getting value by JSONPath is like:
8//! ```
9//! use plainjson::JsonNode;
10//!
11//! fn get_value_by_json_path() {
12//!     let json = r#"{"a": 123, "b": {"c": "hello"}}"#;
13//!     let mut json = JsonNode::parse_single_node(json.as_bytes()).unwrap();
14//!     let c = json.get_str("$.b.c").unwrap();
15//!     assert_eq!(c, Some(String::from("hello")));
16//! }
17//! ```
18//!
19//! Setting value by JSONPath is like:
20//! ```
21//! use plainjson::JsonNode;
22//!
23//! fn set_value_by_json_path() {
24//!     let json = r#"{"a": 123, "b": [3, 2, 1]}"#;
25//!     let mut json = JsonNode::parse_single_node(json.as_bytes()).unwrap();
26//!     json.set_bool("$.b[1]", true).unwrap();
27//!
28//!     assert_eq!(json.to_string(), r#"{"a": 123, "b": [3, true, 1]}"#)
29//! }
30//! ```
31//!
32//! If you need to access low-level JSON tags, use JsonTag:
33//! ```
34//! use plainjson::JsonTag;
35//!
36//! fn fix_json() {
37//!     let json = r#"{"a": test, "b": "world"}"#;
38//!     let mut tags = JsonTag::parse(json.as_bytes()).unwrap();
39//!     tags[3] = JsonTag::Literal(String::from(r#""test""#));
40//!
41//!     assert_eq!(JsonTag::to_string(&tags), r#"{"a": "test", "b": "world"}"#);
42//! }
43//! ```
44//!
45//! This library is licensed under <a href="LICENSE">MIT license</a>.
46
47mod filter_expression;
48mod json_node;
49mod json_path;
50mod json_tag;
51mod peekable_codepoints;
52
53pub use crate::json_node::JsonNode;
54pub use crate::json_tag::JsonTag;