Download .zip |
Info | Documentation | View files (17) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2018-04-08 (5 months ago) | Not yet rated by the users | Total: 183 This week: 1 | All time: 8,271 This week: 468 |
Version | License | PHP version | Categories | |||
php-json 1.1.7 | MIT/X Consortium ... | 5.6 | PHP 5, Files and Folders, Data types |
Description | Author | |
This class can load and save variable values to JSON files. |
PHP simple library for managing Json files.
This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.
The preferred way to install this extension is through Composer.
To install PHP Json library, simply:
$ composer require Josantonius/Json
The previous command will only install the necessary files, if you prefer to download the entire source code you can use:
$ composer require Josantonius/Json --prefer-source
You can also clone the complete repository with Git:
$ git clone https://github.com/Josantonius/PHP-Json.git
Or install it manually:
Download Json.php, JsonLastError.php and JsonException.php:
$ wget https://raw.githubusercontent.com/Josantonius/PHP-Json/master/src/Json.php
$ wget https://raw.githubusercontent.com/Josantonius/PHP-Json/master/src/JsonLastError.php
$ wget https://raw.githubusercontent.com/Josantonius/PHP-Json/master/src/Exception/JsonException.php
Available methods in this library:
Json::arrayToFile($array, $file);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $array | Array to be converted to JSON. | array | Yes | | | $file | Path to the file. | string | Yes | |
# Return (boolean)
Json::fileToArray($file);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $file | Path or external url to JSON file. | string | Yes | |
# Return (array|false)
JsonLastError::check();
# Return (array|null) ? Null if there are no errors or array with state code and error message.
JsonLastError::getCollection();
# Return (array) ? Collection of JSON errors.
To use this library with Composer:
require __DIR__ . '/vendor/autoload.php';
use Josantonius\Json\Json;
Or If you installed it manually, use it:
require_once __DIR__ . '/Json.php';
require_once __DIR__ . '/JsonLastError.php';
require_once __DIR__ . '/JsonException.php';
use Josantonius\Json\Json;
Example of use for this library:
$array = [
'name' => 'Josantonius',
'email' => 'info@josantonius.com',
'url' => 'https://github.com/josantonius/PHP-Json'
];
$pathfile = __DIR__ . '/filename.json';
Json::arrayToFile($array, $pathfile);
$pathfile = __DIR__ . '/filename.json';
$array = Json::fileToArray($pathfile);
$lastError = JsonLastError::check();
if (!is_null($lastError)) {
var_dump($lastError);
}
$jsonLastErrorCollection = JsonLastError::getCollection();
To run tests you just need composer and to execute the following:
$ git clone https://github.com/Josantonius/PHP-Json.git
$ cd PHP-Json
$ composer install
Run unit tests with PHPUnit:
$ composer phpunit
Run PSR2 code standard tests with PHPCS:
$ composer phpcs
Run PHP Mess Detector tests to detect inconsistencies in code style:
$ composer phpmd
Run all previous tests:
$ composer tests
This library uses exception handler that you can customize.
If you would like to help, please take a look at the list of issues or the To Do checklist.
Pull requests
composer install
to install the dependencies.
This will also install the dev dependencies.composer fix
to excute code standard fixers.Thank you to all the people who already contributed to this project!
<img alt="peter279k" src="https://avatars2.githubusercontent.com/u/9021747?v=4&s=117" height="117" width="117"> | :---:| peter279k|
The file structure from this repository was created with PHP-Skeleton.
This project is licensed under MIT license. See the LICENSE file for more info.
2016 - 2018 Josantonius, josantonius.com
If you find it useful, let me know :wink:
Files |
File | Role | Description | ||
---|---|---|---|---|
src (2 files, 1 directory) | ||||
tests (2 files) | ||||
.editorconfig | Data | Auxiliary data | ||
.php_cs.dist | Example | Example script | ||
.travis.yml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONDUCT.md | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.xml | Data | Auxiliary data | ||
phpmd.xml | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
README-ES.md | Doc. | Documentation | ||
README.md | Doc. | Documentation |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Exception (1 file) | ||||
Json.php | Class | Class source | ||
JsonLastError.php | Class | Class source |
Files | / | tests |
File | Role | Description |
---|---|---|
JsonLastErrorTest.php | Class | Class source |
JsonTest.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.