Changed code to clear json before editing next element