falbar / helper-json
Helper for work with json.
Installs: 26
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/falbar/helper-json
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"}"