PHPackages                             kalimulhaq/json-query - 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. kalimulhaq/json-query

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

kalimulhaq/json-query
=====================

Build Laravel Query Using JSON Query String

v1.0.7(4y ago)0162MITPHPPHP ^7.2|^8.0

Since Aug 9Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kalimulhaq/json-query)[ Packagist](https://packagist.org/packages/kalimulhaq/json-query)[ Docs](https://github.com/kalimulhaq/json-query)[ RSS](/packages/kalimulhaq-json-query/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (4)Versions (8)Used By (0)

A JSON query language for your Laravel/Lumen API
================================================

[](#a-json-query-language-for-your-laravellumen-api)

[![Latest Version on Packagist](https://camo.githubusercontent.com/eb7929116805fdc4621075498cbdc062a3ea654cb251b7e107503fc0a6a1af01/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b616c696d756c6861712f6a736f6e2d71756572792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kalimulhaq/json-query)[![Total Downloads](https://camo.githubusercontent.com/36101080f73b7729fcea9b114b06c7c4acc90b18dbcefb0dfbb4c2826dfaef6d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b616c696d756c6861712f6a736f6e2d71756572792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kalimulhaq/json-query)

JsonQuery is a query language for your Laravel/Lumen API, which convert JSON query to Laravel Eloquent ORM query.

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

[](#installation)

You can install the package via composer:

```
composer require kalimulhaq/json-query
```

Usage
-----

[](#usage)

```
use Illuminate\Http\Request;
use Kalimulhaq\JsonQuery\JsonQueryFacade as JsonQuery;

class UsersController extends Controller {

    public function index(Request $request) {
        $this->user = $request->user();
        $json2query = JsonQuery::init('App\User', $request->filter);
        $json2query->buildQuery();
        $json2query->buildResult($request->limit, $request->page);
        $result = $json2query->result();
        $meta = $json2query->meta();
        return response()->json(['data' => $result, 'paginator' => $meta]);
    }
}
```

### Filter

[](#filter)

`filter` is a valid JSON string of the following form

```
{
  "select": [],
  "where": {},
  "order": [],
  "include": [],
  "include_count": [],
  "scopes": []
}
```

#### Example

[](#example)

```
{
  "select": ["id","first_name","last_name","email","phone"],
  "where": {
    "wildcard": {
      "fields": ["first_name","last_name","email","role.name"],
      "value": "any keyword"
    },
    "and": [
      {
        "field": "email",
        "operator": "like",
        "value": "test@email.com"
      },
      {
        "field": "phone",
        "value": "123456789"
      },
      {
        "or": [
          {
            "field": "first_name",
            "operator": "like",
            "value": "kalim"
          },
          {
            "field": "first_name",
            "operator": "like",
            "value": "juli"
          }
        ]
      },
      {
        "field": "role",
        "operator": "where_has",
        "value": {
          "and": [
            {
              "field": "name",
              "value": "admin"
            }
          ]
        }
      }
    ]
  },
  "include": [
    {
      "relation": "role",
      "select": ["id","name"],
      "include": [
        {
          "relation": "permission",
          "select": ["id","name"]
        }
      ]
    }
  ],
  "include_count": [
    {
      "relation": "task"
    }
  ],
  "order": [
    {
      "field": "first_name",
      "order": "asc"
    },
    {
      "field": "last_name",
      "order": "asc"
    }
  ]
}
```

### Select

[](#select)

`select` is an array of columns to select from the base model, If removed `*` will be used

### Where

[](#where)

`where` is a valid json object used to construct the `WHERE` clause

```
{
  "and": [],
  "or": [],
  "field": "",
  "value": "",
  "operator": "",
  "sub_operator": ""
}
```

#### and

[](#and)

to combine the where clause with `AND`

#### or

[](#or)

to combine the where clause with `OR`

Both `and` and `or` are arrays of objects, each object is representing one `where` clause

```
{
  "field": "",
  "value": "",
  "operator": "",
  "sub_operator": ""
}
```

If `operator` removed `=` will be used as a default operator

The (optional) outside `field, value, operator, sub_operator` make a singal where clause which will be combined with `AND` with the `and` and `or` groups.

#### field

[](#field)

column name or relationship name, if operator is `has`, `not_has`, `where_has`, or `where_not_has` the field will be consider is a relationship

#### value

[](#value)

any type of value to search. if operator is `has`, `not_has`, `where_has`, or `where_not_has` the value will be an object of `where` type

#### operator

[](#operator)

supported operators are `=`, `!=`, ``, `=`, `between`, `not_between`, `in`, `not_in`, `null`, `not_null`, `date`, `day`, `moth`, `year`, `time`, `like`, `has`, `not_has`, `where_has`, and `where_not_has`

#### sub\_operator

[](#sub_operator)

sub operator is only required if `operator` is `has` or `not_has`, and supported sub operators are `=`, `!=`, ``, `=`

Order
-----

[](#order)

Order is used to order the rows. `order` is An array of objects

```
[
    {
      "field": "first_name",
      "order": "asc"
    }
]
```

Include
-------

[](#include)

In order to includes related models. `include` is an array of objects with same structure of the root `filter` (see above) object with extra property `relation`.

```
{
  "relation":"",
  "select": [],
  "where": {},
  "order": [],
  "include": [],
  "include_count": [],
  "scopes": []
}
```

Include Count
-------------

[](#include-count)

In order to includes related models count. `include_count` is an array of objects.

```
{
  "relation":"",
  "where": {}
}
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Credits
-------

[](#credits)

- [Kalim ul Haq](https://github.com/kalimulhaq)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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

Every ~101 days

Recently: every ~77 days

Total

7

Last Release

1492d ago

PHP version history (2 changes)1.0.0PHP ^7.2

1.0.2PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ffed9894b1c798cde62f4ceae0935a176e08d3aab2c80352880d6245f555cb2?d=identicon)[kalimulhaq](/maintainers/kalimulhaq)

---

Top Contributors

[![kalimulhaq](https://avatars.githubusercontent.com/u/6983682?v=4)](https://github.com/kalimulhaq "kalimulhaq (6 commits)")

---

Tags

json-querykalimulhaq

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kalimulhaq-json-query/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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