Have you tried “Reset” option in the 2nd Loop?(with an expression relative to the last node runned before the 2nd Loop).. eg :
{{ $prevNode.name === ‘SetJson’ }}
Try maybe as well a sub-workflow for that part,(this is how n8n recommends?) avoiding loops inline that needs downstream precessing and consumption of resources may be hight.
Cheers!
P.S found this relevant topic from a respected community staff member: