falbar / helper-json
This package is abandoned and no longer maintained.
The author suggests using the akbsit/helper-json package instead.
Helper for work with json.
1.0.4
2023-11-26 19:50 UTC
Requires
- php: ^8.1
- ext-json: *
README
Install
To install package, you need run command:
composer require akbsit/helper-json
Examples
- Check string:
$sData = '{"key1":"value1","key2":"value2"}'; $bFlag = JsonHelper::isJson($sData);
- JSON string to array:
$sData = '{"key1":"value1","key2":"value2"}'; $arData = JsonHelper::make()->data($sData)->decode();
array(2) {
["key1"]=> string(6) "value1"
["key2"]=> string(6) "value2"
}
- JSON file to array
$sPath = 'data.json'; // in file string {"key1":"value1","key2":"value2"} $arData = JsonHelper::make()->data($sPath)->decode();
array(2) {
["key1"]=> string(6) "value1"
["key2"]=> string(6) "value2"
}
- Array to JSON string:
$arData = [ 'key1' => 'value1', 'key2' => 'value2', ]; $sData = JsonHelper::make()->data($arData)->encode();
string(33) "{"key1":"value1","key2":"value2"}"