Use typeof to check object before JSON.stringify