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 the Json elecArray = Json.emptyObject; inside of the loop should fix this.

That worked perfectly. Many thanks!