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:
Sukhwinder Dhillon 2026-03-25 15:11:05 +01:00 committed by GitHub
parent f8d4f92566
commit b60448bc77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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";
}