Tightened and added test for error handling of malformed JSON