krcgk/php-json-minifier

1.0.0 2017-09-04 13:15 UTC

README

Configuration

<?php

use Krcgk\JsonMinifier\JsonMinifier;

$jsonMinifier = new JsonMinifier();

$jsonMinifier->syncKeys([
    'firstName' => 'fN',
    'lastName' => 'lN',
    'emailAddress' => 'eA'
]);

Minify Usage

<?php

$jsonObject = '{"firstName":"Gokhan","lastName":"Karaca","emailAddress":"gokhan@karaca.com"}';
$jsonCollection = '[{"firstName":"Gokhan","lastName":"Karaca","emailAddress":"gokhan@karaca.com"},{"firstName":"Gokhan","lastName":"Karaca","emailAddress":"gokhan@karaca.com"}]';


$outputObject = $jsonMinifier->minifyFromJson($jsonObject);
$outputCollection = $jsonMinifier->minifyFromJson($jsonCollection);

// {"fN":"Gokhan","lN":"Karaca","eA":"gokhan@karaca.com"}
// [{"fN":"Gokhan","lN":"Karaca","eA":"gokhan@karaca.com"},{"fN":"Gokhan","lN":"Karaca","eA":"gokhan@karaca.com"}]

Unminify Usage

<?php

$jsonObject = '{"fN":"Gokhan","lN":"Karaca","eA":"gokhan@karaca.com"}';
$jsonCollection = '[{"fN":"Gokhan","lN":"Karaca","eA":"gokhan@karaca.com"},{"fN":"Gokhan","lN":"Karaca","eA":"gokhan@karaca.com"}]';


$outputObject = $jsonMinifier->unminifyFromJson($jsonObject);
$outputCollection = $jsonMinifier->unminifyFromJson($jsonCollection);

// {"firstName":"Gokhan","lastName":"Karaca","emailAddress":"gokhan@karaca.com"}
// [{"firstName":"Gokhan","lastName":"Karaca","emailAddress":"gokhan@karaca.com"},{"firstName":"Gokhan","lastName":"Karaca","emailAddress":"gokhan@karaca.com"}]

Planning

  • Depth Minify and Unminify

Licence

MIT license