JsonRuleEngine.Net 1.0.12

Additional Details

This version contains a few bugs which can be critical in certain conditions. Consider upgrading to the last version

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonRuleEngine.Net --version 1.0.12
                    
NuGet\Install-Package JsonRuleEngine.Net -Version 1.0.12
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonRuleEngine.Net" Version="1.0.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsonRuleEngine.Net" Version="1.0.12" />
                    
Directory.Packages.props
<PackageReference Include="JsonRuleEngine.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JsonRuleEngine.Net --version 1.0.12
                    
#r "nuget: JsonRuleEngine.Net, 1.0.12"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JsonRuleEngine.Net@1.0.12
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JsonRuleEngine.Net&version=1.0.12
                    
Install as a Cake Addin
#tool nuget:?package=JsonRuleEngine.Net&version=1.0.12
                    
Install as a Cake Tool

Build status

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 complexes conditions in database. The purpose of this library is to provide a simple way to store and transform to SQL query (or Linq) nested conditional rules.

Json format of queries

Here is the basic JSON format used to stores the 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
    _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"
    }
};
var list = datas.Where(expression).ToList();

Advanced usages

Product 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.126 25,359 11/25/2024
1.0.125 333 11/15/2024
1.0.124 494 10/29/2024
1.0.122 604 10/8/2024
1.0.121 338 10/3/2024
1.0.119 479 9/11/2024
1.0.118 294 9/9/2024
1.0.117 324 9/3/2024
1.0.116 310 9/3/2024
1.0.115 291 9/3/2024
1.0.114 284 9/1/2024
1.0.113 268 8/30/2024
1.0.112 479 7/27/2024
1.0.111 292 7/25/2024
1.0.110 388 7/16/2024
1.0.109 262 7/16/2024
1.0.108 529 6/25/2024
1.0.107 297 6/22/2024
1.0.106 314 6/21/2024
1.0.12 1,643 11/11/2020 1.0.12 is deprecated because it has critical bugs.
Loading failed