Corrected a bug in the loop for detecting errors and continuing the json generation process.