I am trying to append an array to a Json variable but it ends up repeating the last element over the entire array. For example, if my array should be {"prop":"test1"},{"prop":"test 2"},{"prop":"test3"}, it comes out as {"prop":"test3"},{"prop":"test3"},{"prop":"test3"}.

My most recent attempt is:

Json elecArray = Json.emptyObject;
result["elec"] = Json.emptyArray;
	
foreach(ELEC; elecColl.find(["committee":orgID]))
{
     elecArray["prop"] = ELEC["proposal"].toJson;
     elecArray["id"] = ELEC["_id"].toJson;

     if (ELEC["ballotClosed"].get!bool is false)
     {
    	elecArray["res"] = "OPEN";
     } else if (ELEC["numFavor"].get!long > ELEC["numOppose"].get!long) {
    	elecArray["res"] = "PASS";
     } else {
    	elecArray["res"] = "FAIL";
     }
     result["elec"].appendArrayElement(elecArray);
}

Or simplified:

Json elecArray = Json.emptyObject;
result["elec"] = Json.emptyArray;
	
foreach(ELEC; elecColl.find(["committee":orgID]))
{
     elecArray["prop"] = ELEC["proposal"].toJson;
     elecArray["id"] = ELEC["_id"].toJson;


     result["elec"].appendArrayElement(elecArray);
}