JsonToLinq 1.0.0-rc916

This is a prerelease version of JsonToLinq.
There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonToLinq --version 1.0.0-rc916
                    
NuGet\Install-Package JsonToLinq -Version 1.0.0-rc916
                    
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="JsonToLinq" Version="1.0.0-rc916" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsonToLinq" Version="1.0.0-rc916" />
                    
Directory.Packages.props
<PackageReference Include="JsonToLinq" />
                    
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 JsonToLinq --version 1.0.0-rc916
                    
#r "nuget: JsonToLinq, 1.0.0-rc916"
                    
#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 JsonToLinq@1.0.0-rc916
                    
#: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=JsonToLinq&version=1.0.0-rc916&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=JsonToLinq&version=1.0.0-rc916&prerelease
                    
Install as a Cake Tool

JsonToLinq

JsonToLinq - lightweight C# library that converts JSON-based query definitions into LINQ expressions. Ideal for building dynamic filters, predicates, and queries.

🎯 Use Cases

JsonToLinq can be applied in various scenarios where dynamic, runtime-defined queries are needed. Examples include:

  • Server-side filtering: Apply JSON-defined filters received from front-end applications to collections or database queries.
  • Dynamic reporting: Build complex filters and predicates for reports without hardcoding logic.
  • Custom dashboards: Let users define queries for dashboards dynamically and translate them to LINQ expressions.
  • EF Core / Entity Framework queries: Map JSON filters directly to LINQ queries executed on the database.
  • Audit & logging filters: Dynamically select subsets of data based on JSON rules for auditing or logging purposes.

πŸš€ Quick Start

πŸ—„οΈ With EF, create predicates using JsonLinq.ParseFilterExpression(json).

using Neomaster.JsonToLinq;

var users = source.Where(
  """
  {
    "Logic": "&&",
    "Rules": [
      { "Field": "balance", "Operator": "=", "Value": 0 },
      {
        "Logic": "||",
        "Rules": [
          { "Field": "lastVisitAt", "Operator": "=", "Value": null },
          { "Field": "lastVisitAt", "Operator": "<=", "Value": "2026-01-01T00:00:00Z" }
        ]
      }
    ]
  }
  """);

πŸ› οΈ Operators

πŸ‘“ Operators and their handling logic are encapsulated in class ExpressionOperatorMapper. The default operator mapping can be accessed via property Pairs.

πŸ“Œ Default Operators

Operator Base LINQ Expression Description
& Expression.And Bitwise AND
&& Expression.AndAlso Logical AND
| Expression.Or Bitwise OR
|| Expression.OrElse Logical OR
= Expression.Equal Equal
!= Expression.NotEqual Not equal
> Expression.GreaterThan Greater than
>= Expression.GreaterThanOrEqual Greater than or equal
< Expression.LessThan Less than
<= Expression.LessThanOrEqual Less than or equal
in ExpressionOperators.In In collection
as lower in ExpressionOperators.InStrings Element lower-cased in collection
as upper in ExpressionOperators.InStrings Element upper-cased in collection
starts with ExpressionOperators.StartsWith Starts with
as lower starts with ExpressionOperators.StartsWith Element lower-cased starts with
as upper starts with ExpressionOperators.StartsWith Element upper-cased starts with
ends with ExpressionOperators.EndsWith Ends with
as lower ends with ExpressionOperators.EndsWith Element lower-cased ends with
as upper ends with ExpressionOperators.EndsWith Element upper-cased ends with
contains ExpressionOperators.Contains Contains substring
as lower contains ExpressionOperators.Contains Element lower-cased contains substring
as upper contains ExpressionOperators.Contains Element upper-cased contains substring

πŸ” LINQ Translation

All default operators are designed to be translatable by LINQ providers (e.g. Entity Framework Core) and do not rely on client-side evaluation.

πŸ”  Case Sensitivity and Normalization

  1. String comparisons are case-sensitive, depending on the database collation, not on the operators.
  2. The case of string values specified in the filter is never changed automatically.
  3. Case normalization is the client’s responsibility.
  4. Operators with as lower / as upper apply case transformation to the expression being evaluated, not to the filter value. The filter value is used exactly as provided.

πŸ“¦ Filter Collections

  1. A filter collection can be empty, but it is never null.
  2. A filter collection and its elements are never automatically changed.
  3. Operators with as lower / as upper apply string transformations to each element in the source collection before evaluation, leaving the filter collection elements unchanged.

🌟 Add Custom Operators

Fully Custom Operators
JsonLinq.Configure(options =>
{
  options.OperatorMapper = new ExpressionOperatorMapper()
    .Add("=", Expression.Equal)
      .WithAliases("eq", "EQ")
    .AddNot("!=", "=")
      .WithAliases("neq", "NEQ")
    .AddAlias("==", "=")
      .WithNot("<>");
});
Extend Default Operators
JsonLinq.Configure(options =>
{
  options.OperatorMapper = ExpressionOperatorMapper.OnDefault()
    .Add(...
});

πŸ”¬ Demos and Experiments

This repository contains a project with working examples. You are welcome to submit a PR with your own examples, bug reports, or new features. To describe a filter, use the following notation:

πŸ”€ Filter Notation

Syntax
expr = logic[expr(, expr)*]
  • expr - a single rule or a combination of rules
  • logic - an operator used to combine multiple rules, e.g. &&, &, ||, |, or a custom one
Examples
  1. &&[x = null]
  2. &&[a < 0, b > 0]
  3. &&[x = null, ||[a < 0, b > 0]]

πŸ’» Demo Project

This project provides examples of working with EF Core and a PostgreSQL database.

πŸ§ͺ A real database is used instead of in-memory storage, ensuring clean and realistic experiments.

βž• You can add your own examples with other databases or ORMs via a PR.

▢️ Before running the demos, select the first menu item, Prepare Data, to apply migrations and populate the tables with test data.

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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.0 167 1/3/2026
1.0.0-rc923 288 1/2/2026
1.0.0-rc922 123 1/2/2026
1.0.0-rc921 124 1/2/2026
1.0.0-rc920 123 1/2/2026
1.0.0-rc918 118 1/2/2026
1.0.0-rc917 124 1/2/2026
1.0.0-rc916 157 12/20/2025
1.0.0-rc915 161 12/20/2025
1.0.0-rc914 205 12/19/2025
1.0.0-rc913 267 12/19/2025
1.0.0-rc912 270 12/19/2025
1.0.0-rc911 294 12/18/2025
1.0.0-rc910 308 12/17/2025
1.0.0-rc909 293 12/17/2025
1.0.0-rc908 147 12/13/2025
1.0.0-rc907 149 12/13/2025
1.0.0-rc906 148 12/12/2025
1.0.0-rc905 438 12/11/2025
1.0.0-rc904 475 12/9/2025
Loading failed