mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-06-13 10:40:01 -04:00
Fix leading comma in JSON export (#1349)
When exporting JSON with a limit and a page > 1 set, a leading comma is added before the first item because `$offset !== 0` evaluates to true, resulting in invalid JSON. Replace the offset‑based condition with a `$first` flag to track whether any item has been written yet.
This commit is contained in:
parent
f8d4f92566
commit
b60448bc77
1 changed files with 5 additions and 2 deletions
|
|
@ -85,13 +85,16 @@ trait JsonResultSetUtils
|
|||
$offset = 0;
|
||||
}
|
||||
|
||||
$first = true;
|
||||
echo '[';
|
||||
|
||||
do {
|
||||
$query->offset($offset);
|
||||
$result = $query->execute()->disableCache();
|
||||
foreach ($result as $i => $object) {
|
||||
if ($i > 0 || $offset !== 0) {
|
||||
foreach ($result as $object) {
|
||||
if ($first) {
|
||||
$first = false;
|
||||
} else {
|
||||
echo ",\n";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue