Integer "id" value automatically gets updated to string after POST method

35 Views Asked by At

The integer id value got automatically converted to string after executing json-server db.json

I created a simple db.json that stores the user data like this:

  "users": [
    {
      "id": 1,
      "name": "User1",
      "email": "[email protected]",
      "number": "08100000000"
    },
    {
      "id": 2,
      "name": "User2",
      "email": "[email protected]",
      "number": "08111111111"
    },
    {
      "id": 3,
      "name": "User3",
      "email": "[email protected]",
      "number": "09022222222"
    },
    {
      "id": 4,
      "name": "User4",
      "email": "[email protected]",
      "number": "09033333333"
    },

Next, I updated the file to add another user using the POST command via Postman:

{
    "name": "User5",
    "email": "[email protected]",
    "number": "987876757534"
}

I expected the id to be 5 but it was a random string value "da4a". Also, I noticed that that all id values were converted to string, for example "id": "4", after the json-server db.json.

I initially had the latest json-server version installed when I noticed this issue. I uninstalled it and installed the older version npm i [email protected] but the id value is still automatically converted to string, and the id value is also automatically converted to random string value.

0

There are 0 best solutions below