JsonifySQL 0.7.0

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

JsonifySQL

JsonifySQL is a .NET library that allows querying data through a structured JSON request format. It provides flexible filtering, ordering, pagination, and schema discovery capabilities, making it easy to build dynamic, data-driven APIs.


๐Ÿ“ฆ Installation

Install via NuGet Package Manager:

Install-Package JsonifySQL

Or via .NET CLI:

dotnet add package JsonifySQL

โœจ Features

  • ๐Ÿ” Query data using a powerful and intuitive JSON format
  • ๐Ÿงพ Discover available schemas via schema requests
  • ๐Ÿ”— Join related data with configurable relationships
  • ๐Ÿ“„ Apply dynamic filters and ordering
  • ๐Ÿ“Š Use aggregation functions (sum, avg, min, max)
  • ๐Ÿ“ƒ Support for both offset and cursor-based pagination
  • ๐Ÿ‘ฅ Profile-based access control to queryable objects

โš™๏ธ Configuration

Define searchable objects using a jsonifysql.conf file:

{
  "clients": {
    "alias": "c",
    "visibleOnSchemaQuery": true,
    "cursorField": {
      "name": "cid",
      "type": "integer"
    },
    "fields": {
      "cid": { "type": "integer", "description": "Client identifier" },
      "name": { "type": "string", "description": "Name of the client" }
    },
    "relations": {
      "docs": { "joinField": "cid", "onField": "cid" }
    },
    "fixedOrderBy": {
      "cid": "ASC"
    },
    "access": ["Admin", "DefaultUser"]
  }
}

Optional elements: relations, fixedConditions, fixedMerges, fixedOrderBy, and forProfile.


๐Ÿš€ Usage

1. Register Services

In your Startup.cs or Program.cs:

builder.Services.AddJsonifySQL("path to the jsonifysql.conf file");
builder.Services.AddScoped<IJsonifySQLParser, PostgresJsonifySQL>(); // For PostgreSQL

2. Inject and Use the Parser

public class MySearch
{
    private readonly IJsonifySQLParser _jsonifyParser;

    public MySearch(IJsonifySQLParser jsonifySQLParser)
    {
        _jsonifyParser = jsonifySQLParser;
    }

    public async Task<object> DoSearch(string jsonQuery)
    {
	object? finalResult = null;
	
        var parserResult = _jsonifyParser.ParseJsonQuery(jsonQuery, profile: userProfile, parameterValues: parameters);

        if (!parserResult.Success)
            return parserResult.ParseStatusMessage;

        if (parserResult.IsDataQuery)
        {
            // Execute raw SQL: parserResult.FinalQuery & parserResult.PaginationQuery
	    // if using dapper, you can use the query multiple function and execute the two statements
        }

        if (parserResult.IsSchemaQuery)
        {
            finalResult = JsonSerializer.Deserialize<object>(parserResult.SchemaResponse, new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                WriteIndented = true
            });
        }
		
	return finalResult;
    }
}

๐Ÿ“˜ Example JSON Requests

Simple Query

{
  "query": {
    "clients": {
      "select": ["cid", "name"]
    }
  }
}

With Filter

{
  "query": {
    "clients": {
      "select": ["cid", "name"],
      "where": {
        "name": { "ct": "John" }
      }
    }
  }
}

With Pagination

Cursor-based:

{
  "query": {
    "clients": {
      "select": ["cid", "name"]
    },
    "page": {
      "size": 100,
      "after": "cursorvalue"
    }
  }
}

Offset-based:

{
  "query": {
    "clients": {
      "select": ["cid", "name"]
    },
    "page": {
      "size": 100,
      "current": "1"
    }
  }
}

With Ordering

{
  "query": {
    "clients": {
      "select": ["cid", "name"],
      "orderBy": {
        "name": "ASC"
      }
    }
  }
}

Schema Request

{
  "schema": {}
}

๐Ÿ”Ž Supported Operators

Comparison Operators

Operator Meaning
eq Equals to
neq Not equals to
gt Greater than
lt Less than
gte Greater or equal to
lte Less or equal to
sw Starts with
ew Ends with
ct Contains
in In
matches Full-text match (vector fields only)

Logical Operators

  • and
  • or

Aggregation Functions

  • sum
  • min
  • max
  • avg

๐Ÿ“„ License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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
0.8.1 213 7/4/2025
0.8.0 117 7/4/2025 0.8.0 is deprecated because it has critical bugs.
0.7.0 388 5/27/2025
0.6.0 228 4/24/2025
0.5.0 156 4/24/2025
0.4.0 256 4/11/2025
0.3.0 186 4/10/2025
0.2.0 586 3/25/2025
0.1.0 472 3/25/2025