# JSON parsing in Express

**URL:** <https://forum.kirupa.com/t/json-parsing-in-express/643355>\
**Category:** web dev\
**Created:** [June 24, 2020, 9:33pm UTC](https://forum.kirupa.com/t/json-parsing-in-express/643355 "2020-06-24T21:33:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Umair\_Ashraf](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/umair_ashraf/32/11705_2.png) [@Umair\_Ashraf](https://forum.kirupa.com/u/Umair_Ashraf)\
**Post date:** [June 24, 2020, 9:33pm UTC](https://forum.kirupa.com/t/json-parsing-in-express/643355/1 "2020-06-24T21:33:26Z")

</div>

@senocular one one thing if you can clarify please,

-in back end i am using Node Express and the below code is working fine.  
but can i achieve the same thing i.e saving the incoming data into the DB, like using without app.use(express.json()); statement. i did try to parse the body link x1 = req.body.json(); but that is coming up with error.

```
const express = require("express");
const mysqlx = require("mysql");
const app = express();
app.use(express.json()); // deleted this when parsing data below

app.post("/api/customers", (req, res) => {
let x1 = req.body; // here i tried with let x1 = req.body.json();

  var person = { email: x1.name, password: x1.password };

  connection.query("INSERT INTO users SET ?", person, function (err, results) {

    if (err) throw err;

    console.log(results);

  });

  //query

  let q = "SELECT * from users";

  connection.query(q, function (err, results) {

    if (err) throw err;

    res.json(results);

  });

});
```

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [June 24, 2020, 9:59pm UTC](https://forum.kirupa.com/t/json-parsing-in-express/643355/2 "2020-06-24T21:59:56Z")

</div>

We’re getting off topic of the original thread so I created a new one for you 😉

As for express, this is how express works. You set up the json middleware at the top with `app.use()` and that will be used to format values in `req.body`. `body` is just a data container. Its not used to format.

---

<div class="post-metadata">

**Author:** ![Umair\_Ashraf](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/umair_ashraf/32/11705_2.png) [@Umair\_Ashraf](https://forum.kirupa.com/u/Umair_Ashraf)\
**Post date:** [June 24, 2020, 10:37pm UTC](https://forum.kirupa.com/t/json-parsing-in-express/643355/3 "2020-06-24T22:37:21Z")

</div>

@senocular cool. got it now. Thanks alot 🙂
