beequeue / tweaky
A library for transforming JSON data
dev-master
2016-03-30 23:52 UTC
Requires
- php: >=5.5
- zendframework/zend-stdlib: ~3.0
Requires (Dev)
- pdepend/pdepend: ~2.2
- phploc/phploc: ~2.1
- phpmd/phpmd: ~2.3
- phpunit/phpunit: ~4.8
- satooshi/php-coveralls: ~1.0
- sebastian/phpcpd: ~2.0
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2025-01-18 21:24:55 UTC
README
Tweaky is a library and domain-specific language in JSON notation allowing for the custom transformation of JSON payloads. It is more concerned with altering values than altering form. Primary use-case is for specifying modifications to API responses in a mocking proxy.
Usage
Include via composer:
composer require beequeue/tweaky
Example usage:
use Beequeue\Tweaky\Spec; use Beequeue\Tweaky\Tweaky; $inputJson =<<< END { "a": 1, "b": "original", "c": [ {"key": "first"}, {"key": "second"}, {"key": "last"} ], "d": "leave alone" } END; $specJson =<<< END { "transforms": [{ "a": "{+10}", "b": "new value", "c": { "{[1]}": { "key": "middle" } } }] } END; $spec = new Spec($specJson); $tweaky = new Tweaky($spec); $output = $tweaky->process($inputJson); echo json_encode($output, JSON_PRETTY_PRINT);
will output:
{
"a": 11,
"b": "new value",
"c": [
{
"key": "first"
},
{
"key": "middle"
},
{
"key": "last"
}
],
"d": "leave alone"
}