Added check before forcing JSON.stringify