JsonToLinq 1.0.0-rc916
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
<PackageReference Include="JsonToLinq" Version="1.0.0-rc916" />
<PackageVersion Include="JsonToLinq" Version="1.0.0-rc916" />
<PackageReference Include="JsonToLinq" />
paket add JsonToLinq --version 1.0.0-rc916
#r "nuget: JsonToLinq, 1.0.0-rc916"
#:package JsonToLinq@1.0.0-rc916
#addin nuget:?package=JsonToLinq&version=1.0.0-rc916&prerelease
#tool nuget:?package=JsonToLinq&version=1.0.0-rc916&prerelease
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
- String comparisons are case-sensitive, depending on the database collation, not on the operators.
- The case of string values specified in the filter is never changed automatically.
- Case normalization is the clientβs responsibility.
- Operators with
as lower/as upperapply case transformation to the expression being evaluated, not to the filter value. The filter value is used exactly as provided.
π¦ Filter Collections
- A filter collection can be empty, but it is never
null. - A filter collection and its elements are never automatically changed.
- Operators with
as lower/as upperapply 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 ruleslogic- an operator used to combine multiple rules, e.g.&&,&,||,|, or a custom one
Examples
&&[x = null]&&[a < 0, b > 0]&&[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 | 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. 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. |
-
.NETStandard 2.1
- System.Text.Json (>= 9.0.10)
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 |