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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! # Overview
//! `serde_filter` is a library crate that provides filtering abstractions for JSON objects and arrays
//! using `serde` as a backend. It allows you to easily filter and transform complex JSON structures by
//! providing a set of configurable filters.
//!
//! The crate provides a number of out-of-the-box filters for common use cases, such as filtering by key
//! or value, flattening nested objects and arrays, and more. You can also implement your own filters
//! by implementing the `Filter` trait.
//!
//! ## Using Pre-Built Filters
//! ```
//! use serde_filter::prelude::*;
//! use serde_json::json;
//!
//! fn main() where {
//! let json = serde_json::json!({
//! "Object" : {
//! "explanation": "test",
//! "activeRegionNum": 9876897,
//! },
//! "2022": {
//! "Object" : {
//! "explanation": "test",
//! "activeRegionNum": 1380402,
//! }
//! }
//! });
//! let nums: Vec<u64> = filter::<Match<u64>>(json, &Match::new("activeRegionNum")).unwrap();
//! assert_eq!(nums, vec![9876897u64, 1380402u64]);
//! }
//! ```
/// The Filter trait and Adhoc filter function
/// Flattens a JSON object into a single level
/// ### Example
/// ```no_run
/// use serde_filter::prelude::*;
///
/// let json = serde_json::json!({
/// "a": {
/// "b": {
/// "c": {
/// "d": "value"
/// }
/// }
/// },
/// "e": "value"
/// });
///
/// let expected = serde_json::json!({
/// "a.b.c.d": "value",
/// "e": "value"
/// });
///
/// let flattener = Flatten::default(); // default delimiter is '.'
/// let result = filter::<Flatten>(json, &flattener).unwrap();
/// println!("{:?}", result);
/// assert_eq!(result, expected);
/// The Ignore filter
/// The Match filter
/// Re-export filters