ReferenceError: Json is not defined

javascript, node.js

Solution

You have capitalization error on your JSON variable name. You need to use -

JSON.stringify(url)

not -

Json.stringify(url)

See the docs.

Problem

I am using express and Node.js. When I run the function below to get the value of an URL, `Json.stringify(url)` gives me the error. ReferenceError: Json is not defined. ``` app.get("/id", function (req, res, next) { var id = req.param("id"); connection.query('SELECT `url` FROM dynamic_url where id =' + req.param("id"), function (error, rows, fields) { if (err) { return next(err); } var url; if (rows.length === 0) { url = 'URL not available in database' } else { url = rows[0].url; } var i = Json.stringify(url); res.redirect(i); }); }); ```

Original source