PHPackages                             johnitvn/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. johnitvn/json-query

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

johnitvn/json-query
===================

Parser, create, edit, query and do validate json file.

1.0.2(10y ago)64271[1 issues](https://github.com/johnitvn/json-query/issues)1Apache-2.0PHPPHP &gt;=5.3.2

Since Jul 22Pushed 10y ago1 watchersCompare

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

READMEChangelog (3)DependenciesVersions (4)Used By (1)

Json Query
==========

[](#json-query)

[![Latest Stable Version](https://camo.githubusercontent.com/3f87c19b2f174f0ea713770c801819abf9f29beca9f61a7765be9366da1fa9c4/68747470733a2f2f706f7365722e707567782e6f72672f6a6f686e6974766e2f6a736f6e2d71756572792f762f737461626c65)](https://packagist.org/packages/johnitvn/json-query)[![License](https://camo.githubusercontent.com/c6dafcaf56ef4b35d3ca5e7a2930da5ab0fac7380a936b56968675dfb453bc56/68747470733a2f2f706f7365722e707567782e6f72672f6a6f686e6974766e2f6a736f6e2d71756572792f6c6963656e7365)](https://packagist.org/packages/johnitvn/json-query)[![Total Downloads](https://camo.githubusercontent.com/652ffbffac52a5af22fa7e85c94151d74a683720077ada31120eb0015f9e1778/68747470733a2f2f706f7365722e707567782e6f72672f6a6f686e6974766e2f6a736f6e2d71756572792f646f776e6c6f616473)](https://packagist.org/packages/johnitvn/json-query)[![Monthly Downloads](https://camo.githubusercontent.com/2a693f8691380ff6982da5bf4078798d224bbdb5688699ba12f88889a4e977c1/68747470733a2f2f706f7365722e707567782e6f72672f6a6f686e6974766e2f6a736f6e2d71756572792f642f6d6f6e74686c79)](https://packagist.org/packages/johnitvn/json-query)[![Daily Downloads](https://camo.githubusercontent.com/b3f942b79e98f3cdf58a24d5e6759d528f40eb8d587a733428aa01c98c1b7cc8/68747470733a2f2f706f7365722e707567782e6f72672f6a6f686e6974766e2f6a736f6e2d71756572792f642f6461696c79)](https://packagist.org/packages/johnitvn/json-query)

A PHP library to parser, create, edit, query and do validate [JSON](http://www.json.org/).

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist johnitvn/json-query "*"

```

or add

```
"johnitvn/json-query": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

The library is intended to be used with nested json structures, or with json data that needs validation. Or in any situation where you would find it is easier to do something like this:

```
$document = new johnitvn\jsonquery\JsonDocument();
$document->addValue('/path/to/nested/array/-', array('firstName'=> 'Fred', 'lastName' => 'Blogg'));
$json = $document->toJson(true);
```

which will give you the following json:

```
{
    "path": {
        "to": {
            "nested": {
                "array": [
                    {
                        "firstName": "Fred",
                        "lastName": "Blogg"
                    }
                ]
            }
        }
    }
}
```

You can query this value by calling:

```
$person = $document->getValue('/path/to/nested/array/0');
```

and update it with:

```
$document->addValue('/path/to/nested/array/0/lastName', 'Bloggs');
```

and move it with:

```
$document->moveValue('/path/to/nested/array/0', '/users/-');
$document->tidy();
$json = $document->toJson(true);
```

to end up with:

```
{
    "users": [
        {
            "firstName": "Fred",
            "lastName": "Bloggs"
        }
    ]
}
```

then delete it with:

```
$document->deleteValue('/users/0');

```

Json Query includes an implementation of JSON Schema, version 4. This allows you to validate your data. The following example schema describes an array containing objects whose properties are all required and whose types are defined.

```
$schema = '{
    "items": {
        "properties": {
            "firstName": {"type": "string"},
            "lastName": {"type": "string"}
        },
        "required": ["firstName", "lastName"]
    }
}';
```

Now when you try to add values, Jquery Query will only do so if they are valid. So you have to check.

```
$document->loadSchema($schema);

$result = $document->addValue('/-', array('firstName'=> 'Fred', 'lastName' => 'Bloggs'));
# true

$result = $document->addValue('/-', array('firstName'=> 'Fred', 'lastName' => 3));
# false, lastName is not a string

$result = $document->addValue('/0', array('firstName'=> 'Fred'));
# true, required values are not checked when we are building

# but are checked if we validate directly

$result = $document->validate();
# false - required lastName is missing
```

Without a schema, any value can be added anywhere, of course

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

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 ~0 days

Total

3

Last Release

3952d ago

### Community

Maintainers

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

---

Top Contributors

[![johnitvn](https://avatars.githubusercontent.com/u/8359652?v=4)](https://github.com/johnitvn "johnitvn (7 commits)")

---

Tags

jsonschemajson-parserjson-queryjson creator

### Embed Badge

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

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

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[cerbero/json-parser

Zero-dependencies pull parser to read large JSON from any source in a memory-efficient way.

803474.6k5](/packages/cerbero-json-parser)[hasbridge/json-schema-validator

PHP 5.3 implementation of json schema validation

123456.3k2](/packages/hasbridge-json-schema-validator)[psx/schema

Parse and generate data schema formats

57238.7k18](/packages/psx-schema)

PHPackages © 2026

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