json filter match like mongodb
Find a file
2024-06-05 16:42:11 +02:00
docs docs 2024-02-13 09:53:20 +01:00
examples refactor; add order() fn; add examples 2024-02-09 14:34:12 +01:00
src refactor + size_cmp 2024-06-05 11:38:38 +02:00
.gitignore init 2024-02-09 10:21:27 +01:00
Cargo.lock update deps 2024-06-05 16:42:11 +02:00
Cargo.toml refactor + size_cmp 2024-06-05 11:38:38 +02:00
README.md docs 2024-02-13 09:53:20 +01:00

JSONFilter

jsonfilter is a Rust crate designed to facilitate filtering and comparing JSON values based on specified criteria. It provides functions for comparing JSON values, applying filters to JSON objects, and determining if a filter matches a given JSON object. Think of MongoDBs find() function but as a filter function. For a full syntax guide, see the Filter Documentation

Usage

To use jsonfilter, add it to your Cargo.toml and add the following to your Rust code:

use jsonfilter::{order, matches};

Comparing JSON Values

You can compare two JSON values using the order function:

use serde_json::json;
use std::cmp::Ordering;
use jsonfilter::order;

let a = json!(10);
let b = json!(5);
assert_eq!(order(&a, &b), Ordering::Greater);

Matching Filters

To check if a JSON object matches a filter, use the matches function:

use serde_json::json;
use jsonfilter::matches;

let filter = json!({"name": "John", "age": 30});
let obj = json!({"name": "John", "age": 30, "city": "New York"});

assert!(matches(&filter, &obj));