2017 © Pedro PelĂĄez
 

library php-json-utils

JSON utility class

image

mszewcz/php-json-utils

JSON utility class

  • Thursday, November 2, 2017
  • by mszewcz
  • Repository
  • 0 Watchers
  • 0 Stars
  • 36 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 29 % Grown

The README.md

php-json-utils

JSON utility class, which provides encoding, decoding, base64url encoding and base64url decoding methods., (*1)

Build Status Codacy Badge Codacy Badge, (*2)

Contents

, (*3)

Installation

If you use Composer to manage the dependencies simply add a dependency on mszewcz/php-json-utils to your project's composer.json file. Here is a minimal example of a composer.json:, (*4)

{
    "require": {
        "mszewcz/php-json-utils": ">=1.0"
    }
}

You can also clone or download this respository., (*5)

php-json-utils meets PSR-4 autoloading standards. If using the Composer please include its autoloader file:, (*6)

require_once 'vendor/autoload.php';

If you cloned or downloaded this repository, you will have to code your own PSR-4 style autoloader implementation., (*7)

, (*8)

Usage

To encode data into JSON string:, (*9)

use MS\Json\Utils\Utils;

$obj = new \stdClass();
$obj->flt = 5.5;
$obj->bool = true;

$data = ['int' => 8, 'str' => 'test/Æ©', 'arr' => [$obj]];

$utils = new Utils();
try {
    $encoded = $utils->encode($data);
} catch (\Exception $e) {
    echo $e->getMessage();
}   

To decode JSON string:, (*10)

use MS\Json\Utils\Utils;

$json = '{"int":8,"str":"test/Æ©","arr":[{"flt":5.5,"bool":true}]}';

$utils = new Utils();
try {
    $decoded = $utils->decode($json);
} catch (\Exception $e) {
    echo $e->getMessage();
}   
*/

To base64url encode string:, (*11)

use MS\Json\Utils\Utils;

$data = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eget purus ';
$data.= 'consectetur eros pellentesque ullamcorper. Sed justo tellus, porttitor non ';
$data.= 'porta ac, euismod eu mauris. Nam maximus pretium dapibus. Pellentesque in elit ';
$data.= 'placerat, sagittis justo id, elementum elit. Maecenas dignissim dui ac lectus ';
$data.= 'pretium condimentum. Morbi id ipsum in urna egestas varius in vitae quam. ';
$data.= 'Phasellus efficitur elementum sapien id dictum.';

$utils = new Utils();
$encoded = $utils->base64UrlEncode($data);

To base64url decode string:, (*12)

use MS\Json\Utils\Utils;

$data = 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4';
$data.= 'gTnVuYyBlZ2V0IHB1cnVzIGNvbnNlY3RldHVyIGVyb3MgcGVsbGVudGVzcXVlIHVsbGFtY29ycG';
$data.= 'VyLiBTZWQganVzdG8gdGVsbHVzLCBwb3J0dGl0b3Igbm9uIHBvcnRhIGFjLCBldWlzbW9kIGV1I';
$data.= 'G1hdXJpcy4gTmFtIG1heGltdXMgcHJldGl1bSBkYXBpYnVzLiBQZWxsZW50ZXNxdWUgaW4gZWxp';
$data.= 'dCBwbGFjZXJhdCwgc2FnaXR0aXMganVzdG8gaWQsIGVsZW1lbnR1bSBlbGl0LiBNYWVjZW5hcyB';
$data.= 'kaWduaXNzaW0gZHVpIGFjIGxlY3R1cyBwcmV0aXVtIGNvbmRpbWVudHVtLiBNb3JiaSBpZCBpcH';
$data.= 'N1bSBpbiB1cm5hIGVnZXN0YXMgdmFyaXVzIGluIHZpdGFlIHF1YW0uIFBoYXNlbGx1cyBlZmZpY';
$data.= '2l0dXIgZWxlbWVudHVtIHNhcGllbiBpZCBkaWN0dW0u';

$utils = new Utils();
$decoded = $utils->base64UrlDecode($data);

, (*13)

Contributing

Contributions are welcome. Please send your contributions through GitHub pull requests, (*14)

Pull requests for bug fixes must be based on latest stable release from the master branch whereas pull requests for new features must be based on the developer branch., (*15)

Due to time constraints, I'm not always able to respond as quickly as I would like. If you feel you're waiting too long for merging your pull request please remind ms here., (*16)

Coding standards

We follow PSR-2 coding style and PSR-4 autoloading standards. Be sure you're also following them before sending us your pull request., (*17)

, (*18)

License

php-json-utils is licensed under the MIT License - see the LICENSE file for details., (*19)

The Versions

02/11 2017

dev-develop

dev-develop

JSON utility class

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by MichaƂ Szewczyk

php json utils utilities php-json-utils

01/11 2017

dev-master

9999999-dev

JSON utility class

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by MichaƂ Szewczyk

php json utils utilities php-json-utils

01/11 2017

1.0.0

1.0.0.0

JSON utility class

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

by MichaƂ Szewczyk

php json utils utilities php-json-utils