Skip to content

Support JSON field type and add query interface for json/jsonb fields #4284

Open

Description

@SandPod

Problem to Solve

The current Serverpod database interface does not allow models to declare JSON or JSONB as a field type, nor does it support expressive filtering or querying of arbitrary json/jsonb fields stored in the database, especially when the data structure is unknown or flexible. This limits modeling capabilities as well as advanced querying when working with dynamic or deeply nested JSON fields.

Proposal

  • Add support for JSON (and/or JSONB) as a first-class field type in Serverpod models and the ORM.
  • Introduce a query interface for json/jsonb columns that enables expressive, type-safe querying.
  • Allow filtering and querying based on any json structure and property, using Dart primitives (String, num, bool, List, Map).
  • Support queries such as: 'Find all models where the json field contains a property "name" set to "Alex".'
  • Provide a Dart API that allows building predicates for arbitrary nested json structures using familiar Dart syntax.
  • Support serialization and translation of these queries to efficient SQL, leveraging PostgreSQL's jsonb query operators.
  • Integrate with Serverpod's ORM so that developers can express filters directly in Dart code, regardless of the underlying data shape.

This feature should complement and extend the current capabilities of ColumnSerializable referenced in issue #1591.

API design

TBD, but we would like to provide a typed interface for things that are supported to query on so that the user can not build invalid queries.

Use Case

Useful for storing and retrieving unstructured data.

Alternatives

Alternative approaches considered:

  • Relying on direct SQL queries for json/jsonb fields (less type-safe, bypasses ORM)
  • Implementing custom Dart extensions for specific json structures (limited flexibility)
  • Restricting support to only known json schemas (not dynamic enough for most use cases)

These alternatives were deemed too limiting or not developer-friendly in dynamic data scenarios.

Additional context

See original issue #1591 for broader context. This request now covers both supporting JSON as a native field type in Serverpod models, as well as creating expressive query interfaces for json/jsonb fields in the database. Other serializable comparisons and related operations should be discussed separately.

How experienced are you with this library?

No response

Are you interested in working on a PR for this?

  • I want to work on this

Activity

  1. added theissue type on Nov 24, 2025
  2. added
    area: models
    area: database
    on Nov 24, 2025
  3. changed the title [-]Support JSON field type and add query interface for json/jsonb fields (subissue of #1591)[/-] [+]Support JSON field type and add query interface for json/jsonb fields[/+] on Nov 24, 2025
  4. removed theissue type on Nov 24, 2025
  5. marcelomendoncasoares commented on Nov 28, 2025

    @marcelomendoncasoares
    Collaborator

    This implementation might share common interfaces with #4285.

  6. moved this from Inbox 📫 to Backlog 🗂️ in Serverpod Frameworkson Nov 28, 2025
  7. added a commit that references this issue on Jan 29, 2026
    4db3fbe
  8. nicowalter256 commented on Jun 26, 2026

    @nicowalter256
    Contributor

    is this addressed @marcelomendoncasoares

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: databasearea: models

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions