PHPackages                             daccess1/yii2-json-query-helper - 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. daccess1/yii2-json-query-helper

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

daccess1/yii2-json-query-helper
===============================

Yii2 helper class, used to generate query expressions for JSON columns.

v1.0.0-stable(5y ago)12.8kMITPHP

Since Dec 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/daccess1/yii2-json-query-helper)[ Packagist](https://packagist.org/packages/daccess1/yii2-json-query-helper)[ RSS](/packages/daccess1-yii2-json-query-helper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

JSON Query Helper for Yii 2
===========================

[](#json-query-helper-for-yii-2)

This package provides a `JSONQueryHelper` class, that allows you to generate `yii\db\Expression` expressions for searching by content of JSON columns.

Installation
------------

[](#installation)

The preferred way to install this package is through [composer](http://getcomposer.org/download/):

```
php composer.phar require --prefer-dist daccess1/yii2-json-query-helper

```

Usage
-----

[](#usage)

To use this helper, simply it's result to ActiveQuery builder, like this

```
use daccess1\JSONQueryHelper\JSONQueryHelper;

Model::find()->where(JSONQueryHelper::JSONContains(['json_column', [123, 'value_2']]))->all();
```

The code above will generate an SQL query like this:

```
SELECT * FROM `model` WHERE (JSON_CONTAINS(`json_column`, "123", "$") OR JSON_CONTAINS(`json_column`, "value_2", "$"))
```

Values array can contain any number of elements with mixed types. Parameters array can contain either two or three values, it's structure is similar to default Yii2 query builder params. See examples of possible ways of usage below for more details.

```
//Check if single value is present in JSON
JSONQueryHelper::JSONContains(['json_column', 'value_1'])

//Check if any of values is present in JSON
JSONQueryHelper::JSONContains(['or', 'json_column', ['value_1', 'value_2' ... 'value_n']])
//Equivalent shorthand
JSONQueryHelper::JSONContains(['json_column', ['value_1', 'value_2' ... 'value_n']])

//Check if all values is present in JSON
JSONQueryHelper::JSONContains(['and', 'json_column', ['value_1', 'value_2' ... 'value_n']])
```

You may also set the specific path in for JSON where to find the value. To do so, set the field as an array, with field name as the first item and path as second one. See SQL JSON\_CONTAINS documentation for more details on formatting path. Example usage:

```
//Check if single value is present in JSON field in path 'values'
JSONQueryHelper::JSONContains(['and', ['json_column', '$.values'], ['value_1', 'value_2']])
//This expression will be generated by the code above
JSON_CONTAINS(`json_column`, "value_1", "$.values") AND JSON_CONTAINS(`json_column`, "value_2", "$.values")

//You can specify path with any usage cases shown in examples above, like this
JSONQueryHelper::JSONContains([['json_column', '$.values'], 'value_1'])
JSONQueryHelper::JSONContains([['json_column', '$.values'], ['value_1', 'value_2' ... 'value_n']])
```

Requirements
------------

[](#requirements)

- PHP 7.2 - 7.4

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1974d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a25aae8cff77df7d46105a6702bbe5ea6938862117a91f4d669d2c1b1e4f2c18?d=identicon)[daccess1](/maintainers/daccess1)

---

Top Contributors

[![daccess1](https://avatars.githubusercontent.com/u/19934534?v=4)](https://github.com/daccess1 "daccess1 (12 commits)")

### Embed Badge

![Health badge](/badges/daccess1-yii2-json-query-helper/health.svg)

```
[![Health](https://phpackages.com/badges/daccess1-yii2-json-query-helper/health.svg)](https://phpackages.com/packages/daccess1-yii2-json-query-helper)
```

###  Alternatives

[yii2tech/illuminate

Yii2 to Laravel Migration Package

11315.1k](/packages/yii2tech-illuminate)[mootensai/yii2-relation-trait

Yii 2 Models load with relation, &amp; transaction save with relation

47220.3k9](/packages/mootensai-yii2-relation-trait)[nhkey/yii2-activerecord-history

Storage history of changes to ActiveRecord

46143.4k1](/packages/nhkey-yii2-activerecord-history)[dmstr/yii2-db

Database extensions

19618.8k6](/packages/dmstr-yii2-db)[urbanindo/yii2-dynamodb

DynamoDB extensions for Yii2

1471.4k](/packages/urbanindo-yii2-dynamodb)[spanjeta/yii2-backup

Database Backup and Restore functionality

285.0k1](/packages/spanjeta-yii2-backup)

PHPackages © 2026

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