JsonRuleEngine.Net
1.0.15
This version contains a few bugs which can be critical in certain conditions. Consider upgrading to the last version
See the version list below for details.
dotnet add package JsonRuleEngine.Net --version 1.0.15
NuGet\Install-Package JsonRuleEngine.Net -Version 1.0.15
<PackageReference Include="JsonRuleEngine.Net" Version="1.0.15" />
paket add JsonRuleEngine.Net --version 1.0.15
#r "nuget: JsonRuleEngine.Net, 1.0.15"
// Install JsonRuleEngine.Net as a Cake Addin #addin nuget:?package=JsonRuleEngine.Net&version=1.0.15 // Install JsonRuleEngine.Net as a Cake Tool #tool nuget:?package=JsonRuleEngine.Net&version=1.0.15
JsonRuleEngine.Net
A simple C# rule engine parser and evaluator using a simple json format. This lib is inspired by the json rules engine. (https://github.com/cachecontrol/json-rules-engine)[https://github.com/cachecontrol/json-rules-engine]
Purpose
In some case you'll need to store some complex conditions object in database. The purpose of this library is to provide a simple way to store and transform to linq Expression tree nested conditional rules stored in json in database, filesystem...
Json format of queries
Here is a basic JSON sample that represents rules
{
"separator": "And",
"rules": [
{
"separator": "Or",
"rules": [
{
"field": "Name",
"operator": "equal",
"value": "Assassin's creed"
},
{
"field": "Name",
"operator": "equal",
"value": "Data"
}
]
},
{
"field": "Category",
"operator": "in",
"value": [
"Action",
"Adventure"
]
},
{
"field": "Price",
"operator": "greaterThan",
"value": 5
}
]
}
You can post it to a simple controller using the ConditionRuleSet class
[HttpPost]
public IActionResult PostRules([FromBody] ConditionRuleSet rules) {
// Save it in DB or whatever
if (ModelState.IsValid) {
_db.Add(rules);
_db.SaveChanges();
}
}
Simple use
Installation
You need to install the nuget library
install-package JsonRuleEngine.Net
For evaluating a rule with a single object
string ruleJson = "{
\"field\": \"Name\",
\"operator\": \"equal\",
\"value\": \"Assassin's creed\"
}";
Game objectToTest = new Game() {
Name = "Assassin's creed"
};
bool result = JsonRuleEngine.Evaluate(objectToTest, ruleJson);
return result; // this must display "True"
For filtering a list using an expression
The expression parsed will work with LinqToSql query with EntityFramework Core.
string ruleJson = "{}"
var expression = JsonRuleEngine.ParseExpression<Game>(ruleJson);
var datas = new List<Game>() {
new Game() {
Name = "test"
}
};
// Works with LinqToSql queries
var list = datas.Where(expression).ToList();
The nested rules object
ConditionRuleSet
Field name | Type | Description |
---|---|---|
separator | enum (Or, And) optional | The type of condition rules |
field | string optional | The name of the field used for filtering (Camel sensitive). If the rules properties contains no element this field must be set |
operator | enum (equal,notEqual, lessThan,lessThanInclusive,greaterThan, greaterThanInclusive,in,notIn, contains, doesNotContains) default:equal | The type of method used for comparing values |
value | object optional, default:null | The string value, the number or the object used for egality comparison. In case, the in operator is used, this must be a list of string |
rules | List of ConditionRuleSet optional, default: null | The nested rules contained in the group |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 12.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.125 | 120 | 11/15/2024 | |
1.0.124 | 300 | 10/29/2024 | |
1.0.122 | 366 | 10/8/2024 | |
1.0.121 | 156 | 10/3/2024 | |
1.0.119 | 296 | 9/11/2024 | |
1.0.118 | 111 | 9/9/2024 | |
1.0.117 | 161 | 9/3/2024 | |
1.0.116 | 113 | 9/3/2024 | |
1.0.115 | 103 | 9/3/2024 | |
1.0.114 | 111 | 9/1/2024 | |
1.0.113 | 111 | 8/30/2024 | |
1.0.112 | 292 | 7/27/2024 | |
1.0.111 | 110 | 7/25/2024 | |
1.0.110 | 194 | 7/16/2024 | |
1.0.109 | 86 | 7/16/2024 | |
1.0.108 | 261 | 6/25/2024 | |
1.0.107 | 127 | 6/22/2024 | |
1.0.106 | 130 | 6/21/2024 | |
1.0.103 | 155 | 6/19/2024 | |
1.0.98 | 836 | 2/23/2024 | |
1.0.96 | 226 | 2/12/2024 | |
1.0.93 | 263 | 2/12/2024 | |
1.0.92 | 225 | 2/11/2024 | |
1.0.91 | 205 | 2/11/2024 | |
1.0.87 | 485 | 12/3/2023 | |
1.0.83 | 5,420 | 10/18/2023 | |
1.0.79 | 1,616 | 7/13/2023 | |
1.0.78 | 512 | 6/21/2023 | |
1.0.77 | 973 | 6/13/2023 | |
1.0.76 | 340 | 6/6/2023 | |
1.0.75 | 2,956 | 3/29/2023 | |
1.0.74 | 553 | 2/24/2023 | |
1.0.73 | 601 | 1/26/2023 | |
1.0.71 | 602 | 12/6/2022 | |
1.0.70 | 509 | 12/5/2022 | |
1.0.69 | 544 | 11/25/2022 | |
1.0.68 | 519 | 11/25/2022 | |
1.0.67 | 542 | 11/25/2022 | |
1.0.66 | 511 | 11/25/2022 | |
1.0.65 | 517 | 11/24/2022 | |
1.0.64 | 505 | 11/24/2022 | |
1.0.62 | 890 | 8/17/2022 | |
1.0.61 | 620 | 8/17/2022 | |
1.0.60 | 627 | 8/11/2022 | |
1.0.59 | 642 | 8/9/2022 | |
1.0.58 | 726 | 7/13/2022 | |
1.0.57 | 687 | 6/28/2022 | |
1.0.55 | 635 | 6/28/2022 | |
1.0.54 | 659 | 6/3/2022 | |
1.0.53 | 661 | 5/18/2022 | |
1.0.52 | 718 | 5/18/2022 | |
1.0.47 | 867 | 1/17/2022 | |
1.0.45 | 818 | 1/12/2022 | |
1.0.44 | 670 | 1/10/2022 | |
1.0.43 | 696 | 1/10/2022 | |
1.0.41 | 508 | 1/9/2022 | |
1.0.40 | 1,797 | 11/12/2021 | |
1.0.39 | 657 | 9/13/2021 | |
1.0.38 | 818 | 4/26/2021 | |
1.0.32 | 609 | 4/24/2021 | |
1.0.31 | 614 | 4/22/2021 | |
1.0.30 | 596 | 4/20/2021 | |
1.0.29 | 610 | 4/20/2021 | |
1.0.25 | 593 | 4/19/2021 | |
1.0.23 | 589 | 4/19/2021 | |
1.0.22 | 611 | 4/19/2021 | |
1.0.21 | 617 | 4/19/2021 | |
1.0.15 | 1,153 | 11/11/2020 | |
1.0.12 | 913 | 11/11/2020 |