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.
(cherry picked from commit b60448bc77)
..if there's no limit imposed. PDO runs queries in buffered mode
by default. Fetching without a limit needlessly increases the risk
to require more memory than available.