Have you tried putting it in a try / catch to see is there a json parse error or reference error that maybe isn't getting picked up ?
also have you checked what the value of
jsonValues.items.length
is in the main for loop?
and checking each:
doc.elements.length
could be something odd going with them. I'd put in some print outs " console.log("Length: " + ...); " and see the values / where its stopping.