Skip to content

Commit ed62d0f

Browse files
authored
Merge pull request mavinoo#106 from viest/json
Empty object to safeJson
2 parents 3fc44da + c2dacaa commit ed62d0f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Common/Common.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,18 @@ protected static function is_json($str): bool
6666

6767
protected static function safeJson($jsonData, $asArray = false)
6868
{
69+
if ($jsonData === '{}') {
70+
return $asArray ? [] : '{}';
71+
}
72+
6973
$jsonData = json_decode($jsonData, true);
70-
$safeJsonData = [];
74+
7175
if (!is_array($jsonData)) {
7276
return $jsonData;
7377
}
78+
79+
$safeJsonData = [];
80+
7481
foreach ($jsonData as $key => $value) {
7582
if (self::is_json($value)) {
7683
$safeJsonData[$key] = self::safeJson($value, true);
@@ -82,6 +89,7 @@ protected static function safeJson($jsonData, $asArray = false)
8289
$safeJsonData[$key] = $value;
8390
}
8491
}
92+
8593
return $asArray ? $safeJsonData : json_encode($safeJsonData, JSON_UNESCAPED_UNICODE);
8694
}
8795

0 commit comments

Comments
 (0)