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
//! Server-side helper for clients that address JSON the way
//! [leaf-validator](https://www.npmjs.com/package/leaf-validator) does and
//! PATCH individual leaves.
//!
//! Flatten a document into dotted paths, diff two documents, and match paths
//! against patterns. This is the Rust port of
//! [JsonElementExtensions](https://github.com/stewie1570/JsonElementExtensions).
//! C# extension methods are traits here. Import a trait before calling its
//! methods. That import is what adds `paths_and_values` to
//! [`serde_json::Value`], in the same way a `using` brings an extension method
//! into scope.
//!
//! ```
//! use json_traits::{DiffJson, JsonPaths, JsonScalar, PathPattern};
//! use serde_json::json;
//!
//! let document = json!({
//! "prop1": { "prop2": "value" },
//! "contacts": [{ "info": { "name": "Stewie" } }]
//! });
//!
//! let paths = document.paths_and_values();
//! assert_eq!(paths.get("prop1.prop2"), Some(&JsonScalar::from("value")));
//! assert!("contacts.0.info.name".is_supported_by(["contacts.*.info.name"]));
//! ```
//!
//! Dots inside an object key are not escaped. The key `"a.b"` and the nested
//! object `{"a": {"b": ...}}` produce the same path.
pub use DiffJson;
pub use JsonPaths;
pub use PathPattern;
pub use JsonScalar;
/// The traits that add path, diff, and pattern methods to existing types.