Refactor to serialize message to JSON in the frontend app.