Added error handling for invalid JSON string