Crate serde_filter

Source
Expand description

§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]);
}

Modules§

filter
The Filter trait and Adhoc filter function
flatten
Flattens a JSON object into a single level
ignore
The Ignore filter
matches
The Match filter
prelude
Re-export filters