https://github.com/estahn/json-query-wrapper
A wrapper for the popular command-line JSON processor "jq"
https://github.com/estahn/json-query-wrapper
Last synced: about 1 year ago
JSON representation
A wrapper for the popular command-line JSON processor "jq"
- Host: GitHub
- URL: https://github.com/estahn/json-query-wrapper
- Owner: estahn
- License: mit
- Created: 2016-02-01T13:56:20.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-07T16:46:01.000Z (over 2 years ago)
- Last Synced: 2025-03-26T17:21:41.982Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 60.5 KB
- Stars: 14
- Watchers: 2
- Forks: 4
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Query Wrapper
[](https://packagist.org/packages/estahn/json-query-wrapper)
[](https://packagist.org/packages/estahn/json-query-wrapper)
[](https://www.versioneye.com/user/projects/56af6f3c3d82b90032bff8d7)
[](https://insight.sensiolabs.com/projects/727aca9e-cd01-49b7-94f7-a26030ba5639)
[](https://travis-ci.org/estahn/json-query-wrapper)
[](https://styleci.io/repos/50842755)
json-query-wrapper is a wrapper for the popular command-line JSON processor "[jq](https://stedolan.github.io/jq/)".
## Features
* Easy to use interface
* PHP data type mapping
## Installation
```bash
$ composer require estahn/json-query-wrapper
```
## Usage
### Basic usage
`test.json`:
```json
{
"Foo": {
"Bar": "33"
}
}
```
**Example 1:**
```php
$jq = JsonQueryWrapper\JsonQueryFactory::createWith('test.json');
$jq->run('.Foo.Bar'); # string(33)
```
**Example 2:**
```php
$jq = JsonQueryWrapper\JsonQueryFactory::createWith('test.json');
$jq->run('.Foo.Bar == "33"'); # Returns bool(true)
```
**Example 3:**
```php
$jq = JsonQueryWrapper\JsonQueryFactory::createWith('{"Foo":{"Bar":"33"}}');
$jq->run('.Foo.Bar == "33"'); # Returns bool(true)
```
### Advanced usage
**Example 1:**
```php
$jq = JsonQueryWrapper\JsonQueryFactory::create();
$jq->setDataProvider(new JsonQueryWrapper\DataProvider\File('test.json');
$jq->run('.Foo.Bar == "33"'); # Returns bool(true)
```
## Data Providers
A "Data Provider" provides the wrapper with the necessary data to read from. It's a common interface for several providers. All providers implement the `DataProviderInterface` which essentially returns a path to the file for `jq`.
Available providers:
* `Text` - Regular PHP string containing JSON data
* `File` - A path to a file containing JSON data
## Badge Mania
[](https://scrutinizer-ci.com/g/estahn/json-query-wrapper/build-status/master)
[](https://scrutinizer-ci.com/g/estahn/json-query-wrapper/?branch=master)
[](https://scrutinizer-ci.com/g/estahn/json-query-wrapper/?branch=master)
[](https://www.codacy.com/app/estahn/json-query-wrapper)
[](https://www.codacy.com/app/Codacy/php-codacy-coverage)
## Alternatives
* [jmespath.php](https://github.com/jmespath/jmespath.php) - Declaratively specify how to extract elements from a JSON document, in PHP
* [JSONPath](https://github.com/FlowCommunications/JSONPath) - JSONPath implementation for PHP (based on Stefan Goessner's JSONPath script)