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

This package is auto-updated.

Last update: 2023-11-26 19:59:37 UTC


README

Install

To install package, you need run command:

composer require akbsit/helper-json

Examples

  1. Check string:
$sData = '{"key1":"value1","key2":"value2"}';

$bFlag = JsonHelper::isJson($sData);
  1. 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"
}
  1. 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"
}
  1. Array to JSON string:
$arData = [
    'key1' => 'value1',
    'key2' => 'value2',
];

$sData = JsonHelper::make()->data($arData)->encode();
string(33) "{"key1":"value1","key2":"value2"}"