diff options
Diffstat (limited to 'plugins/API/Renderer/Json2.php')
-rw-r--r-- | plugins/API/Renderer/Json2.php | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/plugins/API/Renderer/Json2.php b/plugins/API/Renderer/Json2.php index bd27810fb8..23f6effe0b 100644 --- a/plugins/API/Renderer/Json2.php +++ b/plugins/API/Renderer/Json2.php @@ -11,8 +11,24 @@ namespace Piwik\Plugins\API\Renderer; use Piwik\Piwik; /** - * Left here for Backward compatibility in Piwik 3.X+ for all users who correctly used format=json2 during Piwik 2.X + * Correct API output renderer for JSON. Includes bug fixes for bugs in the old JSON API + * format. */ class Json2 extends Json { -}
\ No newline at end of file + public function renderArray($array) + { + $result = parent::renderArray($array); + + // if $array is a simple associative array, remove the JSON root array that is added by renderDataTable + if (!empty($array) + && Piwik::isAssociativeArray($array) + && !Piwik::isMultiDimensionalArray($array) + ) { + $result = substr($result, 1, strlen($result) - 2); + } + + return $result; + } +} + |