From b6c7da66d3e3d3b7842e2b3b2da2900d21722f7f Mon Sep 17 00:00:00 2001 From: Jackson Date: Mon, 30 Apr 2018 15:57:14 +1200 Subject: [PATCH] Adjust PhpTek\JSONText\ORM\FieldType\JSONText to supply array when value is empty --- code/ORM/FieldType/JSONText.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/code/ORM/FieldType/JSONText.php b/code/ORM/FieldType/JSONText.php index 3cf6015..f56f6dd 100644 --- a/code/ORM/FieldType/JSONText.php +++ b/code/ORM/FieldType/JSONText.php @@ -250,15 +250,20 @@ public function toSSTypes(array $data) */ public function toArray($value = null) { + $output = []; $value = $value ?: $this->getValue(); - $decoded = json_decode($value, true); - if (is_null($decoded)) { - $msg = 'Decoded JSON is invalid.'; - throw new JSONTextDataException($msg); + // Check for value + if (!empty($value)) { + $output = json_decode($value, true); + + // Check for parse errors + if (JSON_ERROR_NONE !== json_last_error()) { + throw new JSONTextDataException('Unable to parse JSONText value into array: ' . json_last_error()); + } } - return $decoded; + return $output; } /**