jshn: add error handling and fix memory leak in jshn_format().