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
//! This library simply provides:
//! - JsonTag: A low-level JSON tag parser which reads JSON tags from an instance which implements trait std::io::Read
//! - JsonNode: A JSON parser which supports getting or setting value from/to selected JSON nodes by JSONPath
//!
//! Note: Filter expression in JSONPath is not implemented yet, so currently filter expression is not supported.
//!
//! Getting value by JSONPath is like:
//! ```
//! use plainjson::JsonNode;
//!
//! fn get_value_by_json_path() {
//! let json = r#"{"a": 123, "b": {"c": "hello"}}"#;
//! let mut json = JsonNode::parse_single_node(json.as_bytes()).unwrap();
//! let c = json.get_str("$.b.c").unwrap();
//! assert_eq!(c, Some(String::from("hello")));
//! }
//! ```
//!
//! Setting value by JSONPath is like:
//! ```
//! use plainjson::JsonNode;
//!
//! fn set_value_by_json_path() {
//! let json = r#"{"a": 123, "b": [3, 2, 1]}"#;
//! let mut json = JsonNode::parse_single_node(json.as_bytes()).unwrap();
//! json.set_bool("$.b[1]", true).unwrap();
//!
//! assert_eq!(json.to_string(), r#"{"a": 123, "b": [3, true, 1]}"#)
//! }
//! ```
//!
//! If you need to access low-level JSON tags, use JsonTag:
//! ```
//! use plainjson::JsonTag;
//!
//! fn fix_json() {
//! let json = r#"{"a": test, "b": "world"}"#;
//! let mut tags = JsonTag::parse(json.as_bytes()).unwrap();
//! tags[3] = JsonTag::Literal(String::from(r#""test""#));
//!
//! assert_eq!(JsonTag::to_string(&tags), r#"{"a": "test", "b": "world"}"#);
//! }
//! ```
//!
//! This library is licensed under <a href="LICENSE">MIT license</a>.
pub use crateJsonNode;
pub use crateJsonTag;