The problem is that the
foreach
loop just overwrites the same internal associative array entries in each iteration, but every array entry still references the same associative array. Moving theJson elecArray = Json.emptyObject;
inside of the loop should fix this.
That worked perfectly. Many thanks!