https://github.com/akbsit/helper-json
Package for unpacking and packing JSON data.
https://github.com/akbsit/helper-json
array json php
Last synced: 2 months ago
JSON representation
Package for unpacking and packing JSON data.
- Host: GitHub
- URL: https://github.com/akbsit/helper-json
- Owner: akbsit
- License: mit
- Created: 2022-03-12T12:07:58.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-26T19:59:33.000Z (over 2 years ago)
- Last Synced: 2025-12-30T18:17:07.269Z (6 months ago)
- Topics: array, json, php
- Language: PHP
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# helper-json, [Packagist](https://packagist.org/packages/akbsit/helper-json)
## Install
To install package, you need run command:
```bash
composer require akbsit/helper-json
```
## Examples
1. Check string:
```php
$sData = '{"key1":"value1","key2":"value2"}';
$bFlag = JsonHelper::isJson($sData);
```
2. JSON string to array:
```php
$sData = '{"key1":"value1","key2":"value2"}';
$arData = JsonHelper::make()->data($sData)->decode();
```
```text
array(2) {
["key1"]=> string(6) "value1"
["key2"]=> string(6) "value2"
}
```
3. JSON file to array
```php
$sPath = 'data.json'; // in file string {"key1":"value1","key2":"value2"}
$arData = JsonHelper::make()->data($sPath)->decode();
```
```text
array(2) {
["key1"]=> string(6) "value1"
["key2"]=> string(6) "value2"
}
```
4. Array to JSON string:
```php
$arData = [
'key1' => 'value1',
'key2' => 'value2',
];
$sData = JsonHelper::make()->data($arData)->encode();
```
```text
string(33) "{"key1":"value1","key2":"value2"}"
```