Skip to content

JsonContains should allow arrays #11800

Closed

Description

@ertl

Issue description

JsonContains should allow arrays

Expected Behavior

Currently, the JsonContains find operator in TypeORM only accepts objects (Record<string | number | symbol, unknown>). This makes it impossible to query JSONB columns that store arrays in PostgreSQL.

Postgres supports @> containment checks for arrays, e.g.:

SELECT *
FROM my_table
WHERE my_jsonb_column @> '[{"id":"connection_id","value":"1"}]';

But in TypeORM, the following is not possible:

await repo.find({
  where: {
    input: JsonContains([{ id: "connection_id", value: "1" }])
  }
});

Because the type signature restricts JsonContains to objects only.

export declare function JsonContains<
  T extends Record<string | number | symbol, unknown>
>(
  value: T | FindOperator<T>
): FindOperator<any>;

As workaround we use

new FindOperator('jsonContains', JSON.stringify({ id: 'connection_id', value: '1' }))

Actual Behavior

A type error occurs when passing the array.

Steps to reproduce

await repo.find({
  where: {
    input: JsonContains([{ id: "connection_id", value: "1" }])
  }
});

My Environment

Dependency Version
Operating System
Node.js version v24.10.0
Typescript version 5.9.2
TypeORM version 0.3.27

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

Activity

  1. PreAgile commented on Apr 1, 2026

    @PreAgile
    Contributor

    I'd like to take this. The fix should be straightforward — removing the Record constraint on JsonContains's generic to match the pattern used by ArrayContains and other operators. The existing test in #9381 already exercises array containment with an as any cast, confirming the runtime works fine.

  2. added 3 commits that reference this issue on Apr 28, 2026
    73fc3f8
    5e2bc2f
    7c0369e
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions