estahn / json-query-wrapper
Wrapper for jq, a lightweight and flexible command-line JSON processor
Installs: 25 588
Dependents: 1
Suggesters: 0
Security: 0
Stars: 14
Watchers: 3
Forks: 4
Open Issues: 13
Requires
- php: ^7.1|^8
- symfony/process: ^4|^5
Requires (Dev)
- phpunit/phpunit: ^7|^8|^9
- vimeo/psalm: 4.x-dev
- dev-master
- v1.0.0
- v0.2.1
- v0.2.0
- v0.1.2
- v0.1.1
- v0.1.0
- dev-renovate/phpunit-phpunit-10.x
- dev-renovate/github-codeql-action-3.x
- dev-renovate/major-symfony
- dev-renovate/actions-checkout-4.x
- dev-renovate/php-actions-phpunit-3.x
- dev-renovate/github-codeql-action-2.x
- dev-renovate/actions-cache-3.x
- dev-renovate/actions-checkout-3.x
- dev-renovate/php-actions-phpunit-9.x
- dev-renovate/php-actions-composer-6.x
This package is not auto-updated.
Last update: 2024-11-09 19:28:42 UTC
README
json-query-wrapper is a wrapper for the popular command-line JSON processor "jq".
Features
- Easy to use interface
- PHP data type mapping
Installation
$ composer require estahn/json-query-wrapper
Usage
Basic usage
test.json
:
{ "Foo": { "Bar": "33" } }
Example 1:
$jq = JsonQueryWrapper\JsonQueryFactory::createWith('test.json'); $jq->run('.Foo.Bar'); # string(33)
Example 2:
$jq = JsonQueryWrapper\JsonQueryFactory::createWith('test.json'); $jq->run('.Foo.Bar == "33"'); # Returns bool(true)
Example 3:
$jq = JsonQueryWrapper\JsonQueryFactory::createWith('{"Foo":{"Bar":"33"}}'); $jq->run('.Foo.Bar == "33"'); # Returns bool(true)
Advanced usage
Example 1:
$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 dataFile
- A path to a file containing JSON data
Badge Mania
Alternatives
- jmespath.php - Declaratively specify how to extract elements from a JSON document, in PHP
- JSONPath - JSONPath implementation for PHP (based on Stefan Goessner's JSONPath script)