Fix Logic

Fix logic that causes endless loop for json that is malformed. Although I expect it to be valid json I believe this case should be handled.