2017-25 © Pedro Peláez
 

library tweaky

A library for transforming JSON data

image

beequeue/tweaky

A library for transforming JSON data

  • Thursday, March 31, 2016
  • by beequeue
  • Repository
  • 0 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Tweaky

Build Status Coverage Status, (*1)

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., (*2)

Usage

Include via composer:, (*3)

composer require beequeue/tweaky

Example usage:, (*4)

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:, (*5)

{
    "a": 11,
    "b": "new value",
    "c": [
        {
            "key": "first"
        },
        {
            "key": "middle"
        },
        {
            "key": "last"
        }
    ],
    "d": "leave alone"
}

The Versions

31/03 2016

dev-master

9999999-dev

A library for transforming JSON data

  Sources   Download

MIT

The Requires

 

The Development Requires

by Brendan Quigley

mock json transformation