simtabi/json

PHP simple library for managing Json files.


Keywords
php, json, javascript, data exchange, hhvm, File to array, Array to file, JavaScript Object Notation
License
MIT

Documentation

PHP Json library

Latest Stable Version Total Downloads Latest Unstable Version License

PHP simple library for managing Json files.



Installation

The preferred way to install this extension is through composer.

To install PHP Json library, simply:

$ composer require simtabi/json

Requirements

This library is supported by PHP versions 7.0 or higher and is compatible with HHVM versions 3.0 or higher.

To use this library in HHVM (HipHop Virtual Machine) you will have to activate the scalar types. Add the following line "hhvm.php7.scalar_types = true" in your "/etc/hhvm/php.ini".

Quick Start and Examples

To use this class, simply:

require __DIR__ . '/vendor/autoload.php';

use Simtabi\Json\Json;

Available Methods

Available methods in this library:

Json::arrayToFile();
Json::fileToArray();
Json::jsonLastError();

Usage

Example of use for this library:

<?php
require __DIR__ . '/vendor/autoload.php';

use Simtabi\Json\Json;

$array = [
	'name'  => 'Simtabi',
    'email' => 'info@simtabi.com',
    'url'   => 'https://github.com/simtabi/PHP-Json'
];

$pathfile = __DIR__ . '/filename.json';

var_dump(Json::arrayToFile($pathfile, $array)); //bool(true)

/* This will create "filename.json" in the "tests" folder. */

Tests

To use the test class, simply:

<?php
$loader = require __DIR__ . '/vendor/autoload.php';

$loader->addPsr4('Simtabi\\Json\\Tests\\', __DIR__ . '/vendor/simtabi/json/tests');

use Simtabi\Json\Tests\JsonTest;

Available test methods in this library:

JsonTest::testArrayToFile();
JsonTest::testArrayToFileError();
JsonTest::testFileToArray();
JsonTest::testFileToArrayError();

Exception Handler

This library uses exception handler that you can customize.

Contribute

  1. Check for open issues or open a new issue to start a discussion around a bug or feature.
  2. Fork the repository on GitHub to start making your changes.
  3. Write one or more tests for the new feature or that expose the bug.
  4. Make code changes to implement the feature or fix the bug.
  5. Send a pull request to get your changes merged and published.

This is intended for large and long-lived objects.

Repository

All files in this repository were created and uploaded automatically with Reposgit Creator.

Author

Maintained by Simtabi.

Licensing

This project is licensed under MIT license. See the LICENSE file for more info.