better json error handling