PHPackages                             boldtrn/jsonb-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. boldtrn/jsonb-bundle

ActiveLibrary[Database &amp; ORM](/categories/database)

boldtrn/jsonb-bundle
====================

A library adding the support for JSONB columns of PostgreSQL to Doctrine.

v1.2.0(6y ago)57817.6k—2.8%14[1 PRs](https://github.com/boldtrn/JsonbBundle/pulls)MITPHPPHP &gt;=5.3.3CI failing

Since Jul 1Pushed 5y ago6 watchersCompare

[ Source](https://github.com/boldtrn/JsonbBundle)[ Packagist](https://packagist.org/packages/boldtrn/jsonb-bundle)[ Docs](https://github.com/boldtrn/JsonbBundle)[ RSS](/packages/boldtrn-jsonb-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

JsonbBundle
===========

[](#jsonbbundle)

**Doctrine implemented the `jsonb` datatype with Doctrine DBAL 2.6. I recommend using the official Doctrine implementation. If you cannot upgrade feel free to use this bundle. It still works for me in my current production setting. I will upgrade to the doctrine implementation at some point in time, as well.****[Doctrine Mapping Matrix](http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/types.html#mapping-matrix)**

This bundle extends Doctrine to use the `jsonb` datatype that ships with Postgresql 9.4. This bundle is fully compatible with Symfony, but you do not have to use Symfony (see the `composer.json` for dependencies). Please make sure you have Postgresql with a version of at least 9.4 installed before using this bundle. The Bundle allows to create Jsonb fields and use the `@>`,`?` and the `#>>` operator on the Jsonb field. Other Operations can be easily added.

I recently discovered the power of NativeQueries (). Right now I only use NativeQueries when querying. An example is shown below.

[![Build Status](https://camo.githubusercontent.com/cd76b97212bd94e7b54b185c6607405b70e1febda8e42ac93d95b02d2c7858d3/68747470733a2f2f7472617669732d63692e6f72672f626f6c6474726e2f4a736f6e6242756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/boldtrn/JsonbBundle)

Installation
============

[](#installation)

Step 1: Download the Bundle
---------------------------

[](#step-1-download-the-bundle)

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

```
$ composer require "boldtrn/jsonb-bundle:~1.1"
```

Step 2: Add the new Types and Functions to the Config
-----------------------------------------------------

[](#step-2-add-the-new-types-and-functions-to-the-config)

```
# config.yml
doctrine:
    dbal:
        types:
          jsonb: Boldtrn\JsonbBundle\Types\JsonbArrayType
        mapping_types:
          jsonb: jsonb
    orm:
        dql:
            string_functions:
                JSONB_AG:   Boldtrn\JsonbBundle\Query\JsonbAtGreater
                JSONB_HGG:  Boldtrn\JsonbBundle\Query\JsonbHashGreaterGreater
                JSONB_EX:   Boldtrn\JsonbBundle\Query\JsonbExistence
```

Note: There were people having issues with the above configuration. They had the following exception:

```
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
  Unrecognized options "dql" under "doctrine.orm"

```

This was fixed by changing the dql part in the following (add the `entity_managers` between `orm` and `dql`):

```
doctrine:
    orm:
        entity_managers:
            dql:
```

Step 3: Create a Entity and Use the Jsonb Type
----------------------------------------------

[](#step-3-create-a-entity-and-use-the-jsonb-type)

```
/**
 * @Entity
 */
class Test
{

    /**
     * @Id
     * @Column(type="string")
     * @GeneratedValue
     */
    public $id;

    /**
     * @Column(type="jsonb")
     *
     * Usually attrs is an array, depends on you
     *
     */
    public $attrs = array();

}
```

Step 4.1: Write a Repository Method using a NativeQuery
-------------------------------------------------------

[](#step-41-write-a-repository-method-using-a-nativequery)

```
$q = $this
            ->entityManager
            ->createNativeQuery(
                "
        SELECT t.id, t.attrs
        FROM Test t
        WHERE t.attrs @> 'value'
        "
            , $rsm);
```

You only need to setup the `$rsm` ResultSetMapping according to the Doctrine documentation.

Step 4.2: Write a Repository Method that queries for the jsonb using the custom JSONB\_FUNCTIONS
------------------------------------------------------------------------------------------------

[](#step-42-write-a-repository-method-that-queries-for-the-jsonb-using-the-custom-jsonb_functions)

This example shows how to use the contains statement in a WHERE clause. The `= TRUE` is a workaround for Doctrine that needs an comparison operator in the WHERE clause.

```
$q = $this
            ->entityManager
            ->createQuery(
                "
        SELECT t
        FROM E:Test t
        WHERE JSONB_AG(t.attrs, 'value') = TRUE
        "
            );
```

This produces the following Query:

```
SELECT t0_.id AS id0, t0_.attrs AS attrs1 FROM Test t0_ WHERE (t0_.attrs @> 'value') = true
```

This example shows how to query for a value that is LIKE `%d%`The result could be data like:

```
 id |                 attrs
----+--------------------------------------
  4 | {"a": 1, "b": {"c": "abcdefg", "e": true}}

```

```
        $q = $this
            ->entityManager
            ->createQuery(
                "
        SELECT t
        FROM E:Test t
        WHERE JSONB_HGG(t.attrs , '{\"b\",\"c\"}') LIKE '%d%'
        "
            );
```

This produces the following Query:

```
SELECT t0_.id AS id0, t0_.attrs AS attrs1 FROM Test t0_ WHERE (t0_.attrs #>> '{\"object1\",\"object2\"}') LIKE '%a%'
```

Further Information
-------------------

[](#further-information)

The `?` operator is implemented by calling its function `jsonb_exists(column_name, value)` since Doctrine will consider it a parameter placeholder otherwise. The same must be done if you want to implement `?|` and `?&` operators, using `jsonb_exists_any(column_name, value)` and `jsonb_exists_all(column_name, value)` respectively

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity50

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~520 days

Total

4

Last Release

2414d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00b37b37638e284b2704146b56991c2727a927efcbc8c0f7c7c68c3f451df001?d=identicon)[boldtrn](/maintainers/boldtrn)

---

Top Contributors

[![boldtrn](https://avatars.githubusercontent.com/u/1553525?v=4)](https://github.com/boldtrn "boldtrn (61 commits)")[![valepu](https://avatars.githubusercontent.com/u/5619832?v=4)](https://github.com/valepu "valepu (3 commits)")[![adrienbrault](https://avatars.githubusercontent.com/u/611271?v=4)](https://github.com/adrienbrault "adrienbrault (1 commits)")[![ixnv](https://avatars.githubusercontent.com/u/4655259?v=4)](https://github.com/ixnv "ixnv (1 commits)")[![midieuminable](https://avatars.githubusercontent.com/u/4760040?v=4)](https://github.com/midieuminable "midieuminable (1 commits)")[![dunglas](https://avatars.githubusercontent.com/u/57224?v=4)](https://github.com/dunglas "dunglas (1 commits)")[![ddera-printedcom](https://avatars.githubusercontent.com/u/160150573?v=4)](https://github.com/ddera-printedcom "ddera-printedcom (1 commits)")

---

Tags

symfonybundledoctrinepostgresqljsonb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/boldtrn-jsonb-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/boldtrn-jsonb-bundle/health.svg)](https://phpackages.com/packages/boldtrn-jsonb-bundle)
```

###  Alternatives

[fresh/doctrine-enum-bundle

Provides support of ENUM type for Doctrine2 in Symfony applications.

4636.8M12](/packages/fresh-doctrine-enum-bundle)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[sonata-project/doctrine-orm-admin-bundle

Integrate Doctrine ORM into the SonataAdminBundle

46117.7M155](/packages/sonata-project-doctrine-orm-admin-bundle)[omines/datatables-bundle

Symfony DataTables Bundle with native Doctrine ORM, Elastica and MongoDB support

2851.4M6](/packages/omines-datatables-bundle)[prezent/doctrine-translatable-bundle

Integrate the doctrine-translatable extension in Symfony

14698.4k5](/packages/prezent-doctrine-translatable-bundle)[vasek-purchart/doctrine-date-time-immutable-types-bundle

Bundle integration of Doctrine DateTimeImmutable types for Symfony

1085.6k](/packages/vasek-purchart-doctrine-date-time-immutable-types-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
