Repository navigation
Open
Labels
enhancementNew feature or requestfixedThe bug, issue, incident has been fixed.requestA request from the community.
Description
Support First-Class JSON/JSONB Mapping and Querying
Description
Introduce first-class JSON/JSONB support in RepoDB for SQL Server, PostgreSQL, and Oracle, allowing strongly typed .NET objects to be stored, retrieved, and queried against JSON-backed database columns.
The implementation should introduce a DbJsonValue<T> abstraction that handles serialization/deserialization while allowing RepoDB's expression parser to translate property and array access into the database-specific JSON syntax.
Example Model
[Table(nameof(JsonTestClass))]
public record class JsonTestClassValues
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public DbJsonValue<JsonBTestClass> JsonNode { get; set; }
public DbJsonValue<JsonBTestClass>? Object { get; set; }
public DbJsonValue<string[]> Array { get; set; }
}Insert
await connection.InsertAsync(new JsonTestClassValues
{
Id = 1,
Name = "Test",
JsonNode = new JsonBTestClass { Id = 5 },
Object = new JsonBTestClass(),
Array = new[] { "a", "b" }
});Query via ExtractValue
var result = await connection.QueryAsync<JsonTestClassValues>(
x => x.JsonNode.ExtractValue(v => v.Id) == 5);Query via Strongly Typed Value
RepoDB should also recognize access through Value and automatically translate it into the appropriate JSON expression.
var result = await connection.QueryAsync<JsonTestClassValues>(
x => x.JsonNode.Value.Id == 5);Nested objects and array access should follow the same expression-based approach.
Goals
- Introduce
DbJsonValue<T>as a strongly typed JSON value abstraction. - Automatically serialize
Twhen inserting or updating. - Automatically deserialize JSON values when querying.
- Support JSON property access through RepoDB expressions.
- Support nested objects and arrays.
- Translate expressions into provider-specific JSON syntax.
- Support SQL Server, PostgreSQL, and Oracle.
- Keep JSON handling provider-independent from the consumer's perspective.
Acceptance Criteria
DbJsonValue<T>works with Insert, Update, Query, and other applicable RepoDB operations.- JSON values round-trip correctly between .NET and the database.
ExtractValue(...)expressions are translated into native JSON queries.Value.Propertyexpressions are automatically recognized and translated.- Nested properties and array access are supported.
- SQL Server, PostgreSQL, and Oracle have integration tests covering JSON read, write, update, and filtering.
- Existing non-JSON RepoDB behavior remains unaffected.
Reference: AmpScm#25
Reacted by Bert Huijben
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestfixedThe bug, issue, incident has been fixed.requestA request from the community.
Activity
mikependon commentedon Aug 31, 2026
Hi @AntyaDev @rhuijben, I tried to analyze this further and this is a kind of edge-case but it is already supported. Are you aware that you can already do this via Property Handler? Property handler is there to support whatever interceptors you would like to do with your properties against the database types.
Basically, on the above use-case, you can do the following in the bottom.
Then map it fluently like below.
Let me know your thoughts.
mikependon commentedon Aug 31, 2026
More into it. It is on my plan to add the pre-defined PropertyHandlers and Resolvers as I gain insights when expanding the library to many DB providers. They have different requirements on .NET to DB Types conversion, that is why some are needed. I also have challenges supporting the XML in Oracle and MariaDB due to these and some of them I have to put to limitations for now.
rhuijben commentedon Aug 31, 2026
Some things can be handled on this layer, but some db implementations need other overrides. The current property mapping doesn't work intuitively with nullable fields in the database.
(Some cases are more like hidden bugs.. some break nullability annotations, etc.)
I think the nullability of value types should be handled outside these handlers (by RepoDB), which would make things much easier to implement... But may be quite a breaking change.
And especially things like Json (and perhaps vectors) could also use linq query support, and then there needs to be more integration in type mappings on multiple layers, depending on db specifics.
mikependon commentedon Aug 31, 2026
OK, I will evaluate further and then probably we can support this if it is already a use-case you are using there. Do you happen to share to which DB provider did you applied this for? Is it only SQL Server?
mikependon commentedon Aug 31, 2026
In relation to our limitation page, each of the items here are to be user story of the future. I keep adding them here while expanding the library so we all can work together in the future. I hope that this is one of such.
mikependon commentedon Aug 31, 2026
List of DB providers that support XMLs.
XML Support Across RepoDB Database Providers
The table below summarizes the level of native XML support available across the database providers supported by RepoDB.
xml, XQuery,nodes(),value(),query(),exist(), XML indexesxml,XMLPARSE,XMLSERIALIZE, XPath,XMLTABLExml, SQL/XML functions, PostgreSQL-compatible XML functionalityXMLType,XMLQuery,XMLTable,XMLExistsXML, SQL/XML, XPath/XQuery, XML indexesxmltype; XML can be stored asSTRINGorBYTESTEXTorBLOBXMLcolumn typeRecommended RepoDB First-Class XML Support
The following providers are candidates for native
DbXmlValue<T>support:These databases provide native XML data types and database-side XML querying capabilities.
For databases without native XML support, RepoDB could optionally support
DbXmlValue<T>through serialization into the appropriate textual or LOB database type.mikependon commentedon Aug 31, 2026
List of DB providers that support JSON.
JSON Support Across RepoDB Database Providers
The table below summarizes JSON support across the database providers supported by RepoDB.
json,jsonb, JSON operators (->,->>), JSONPath, indexingjson/jsonb, operators, JSONPath and indexingJSONB, JSON operators, containment and inverted indexesJSONtype on modern versions;JSON_VALUE,JSON_QUERY,JSON_TABLE, JSON search/indexingJSON,JSON_EXTRACT,->,->>,JSON_TABLE, JSON functionsjsontype on newer SQL Server versions; historically JSON stored innvarchar, withJSON_VALUE,JSON_QUERY,OPENJSON,JSON_MODIFYJSONis generally an alias forLONGTEXT, with JSON validation/functionsJSONtype in modern ClickHouse plus extensive JSON extraction/processing functionsTEXT/BLOB; JSON1/modern built-in JSON functions and JSONB representationRecommended RepoDB JSON Support
Unlike XML,
DbJsonValue<T>can reasonably become a common RepoDB abstraction across most providers.For example:
Strongly Typed Queries
RepoDB could recognize strongly typed access to JSON properties:
or explicitly:
The RepoDB connector would translate the expression into the appropriate database-specific JSON expression.
Conceptually:
This keeps
DbJsonValue<T>database-independent while allowing each RepoDB connector to use the best JSON capabilities available from its underlying database.rhuijben commentedon Sep 3, 2026
I have the basic support for this working in the AmpScm fork, but I hope we can enhance this later on when db providers improve their support. Postgresql is already some steps ahead and I think SqlServer is working on more too.
Thanks for modelling this here like my initial work... But if somebody has better ideas, please join in, as we might be able to do better. The nice thing about this model is that it allows both native json queries and accessing the object model... like we do with other queries in RepoDB
mikependon commentedon Sep 3, 2026
@rhuijben the model above is from @AntyaDev post in your fork which eventually mimic your implementation. I tried to model it here to see how much extent this capability will be applied to given with the number of providers we are supporting. Can you make a PR of your initial implementation to here?
AntyaDev commentedon Sep 6, 2026
Thanks @mikependon @rhuijben for your input!
I really like the examples with JSON support :)
mikependon commentedon Sep 13, 2026
@rhuijben hi, may I know when can you port some of your versions to main? And while you are doing that, I will do some bug hunting from the issue list.
rhuijben commentedon Sep 13, 2026
Sorry, can't actively work on this right now. Tried to move some info in that report so somebody else can (use some ai to) extract it from my codebase.
mikependon commentedon Sep 20, 2026
Hi All, I have supported this via PropertyHandlers as I stick on the original plan to not impacting the existing architecture. In this PR (or issue #1342), you will that many common and DB provider specific Property Handlers has been introduced.
You will a lot on our documentation at https://repodb.net/propertyhandler/jsontoentitypropertyhandler/.
Basically, the use-case here can be covered by JSON to TEntity handling (vice-versa).
sanirr commentedon Oct 20, 2026
Hi @mikependon
We need to update a few regular columns and replace only one key of a jsonb column, keeping its other keys. Today we use raw SQL:
Is there a typed way to do this in RepoDB, e.g. UpdateAsync with the regular fields plus a partial JSON update for the jsonb column?
mikependon commentedon Oct 20, 2026
Not directly JSON targeting, but you can do the trick via Propery Handler. Have you tried that already?
With property handlers, you handle in C# how to hydrate and pass the contents in/out of model.
AntyaDev commentedon Oct 21, 2026
@mikependon Does PropertyHandler help filter by JSON fields? From what I see, it only helps with mapping, but you still can't write statically typed queries.
mikependon commentedon Oct 23, 2026
@sanirr and @AntyaDev - I fully supported this use case with property handler already. You can use the JsonToEntityPropertyHandler for this case.
Disclaimer: With property handler, it follows the overall architecture of RepoDB.
See sample below for clarity and how to use it cleanly.
Create a new record.
The order column will contain the following JSON value.
{ "OrderNumber": "ORD-1001", "TotalAmount": 1500.00, "ShippingAddress": { "Street": "Main Street 123", "City": "Copenhagen", "Country": "Denmark" } }You can query it like below.
You can also retrieve and update it like below.
Just register it like below.
But I agree with you @AntyaDev that it is only the mapping/hydration that works to this. I can introduce a JsonQueryField for you that is also passable to the Func for filtering.
AntyaDev commentedon Oct 23, 2026
@mikependon I think JsonQueryField can help, but I'm still not 100% sure I understand how you can patch/update the record without fetching it. Most of our cases are just updates without fully hydrating the entity in memory.
mikependon commentedon Oct 23, 2026
@AntyaDev let me think of this, and probably will just wait for @rhuijben's fork from his branch. I just released today the v1.17.0 with only the property handler support. I am planning to end the v1.X in the v1.17.0 as I am moving to v2.0 already, but this one is requires a movement to v1.18.0. Are you able to wait for v2.0, and for now use the RAW? I will spend time taking the fork out from Rhuiben's fork.
AntyaDev commentedon Oct 23, 2026
@mikependon, sure, no worries. It can wait :)
I just wanted to say that the JSON story is very common in the modern SQL world. I forget when I designed tables in a relational model with N layers of JOINS (it makes query execution slow, not to mention all the migration headaches). Today I usually have a table with a few columns for mandatory filtering (common columns like ID, ProjectId, Created, LastUpdated) and the rest is just JSON.
I really like the type-safe experience of writing queries, and this is where RepoDB is super cool! That said, working with JSON still requires a few extra steps and doesn’t quite feel like a first-class experience yet. Not sure if this helps, but I wanted to share this context in case it informs future improvements.
mikependon commentedon Oct 23, 2026
Definitely. Thanks for raising that @AntyaDev. I will revert with @rhuijben about his availability of pushing his work to the core. But, will definitely include the JSON support to the v2.0 on the model level, not just handler.
mikependon commentedon Nov 11, 2026
Hi @rhuijben, how are you? I hope that everything is well on your end. I made a promise to support JSON. I want to have near-zero deviations from your implementation. Will you be able to help me move the capabilities from your fork towards RepoDB master as the upstream branch? I will work on this within the week if this will never move. Thanks!
mikependon commentedon Nov 11, 2026
I have my AI helped me analyze this 'https://github.com/rhuijben/RepoDB' ait is now quite far from where we are. I am thinking if we could start from scratch or push for migrating from fork. There are major risks to do this on current main line,
I also see some code placements that requires refactoring, especially the BaseDbSetting should only contain properties, not functions. Although this is small.
Let me see how can I approach this JSON thing.
mikependon commentedon Nov 11, 2026
I am struggling a bit on this to make a proper balance, but I will approach it with below.
No promise about the same experience of API, but it is with best stretch effort.
mikependon commentedon Nov 11, 2026
Examined the code base and came-up with the same proposal of APIs from fork.
issue-1312-json-crud-sample.md
Supported the JSON all other DB Providers, not just SQL Server and PG…