Skip to content

json-server Converts Numeric "id" Fields to Strings #1636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
RushiLee opened this issue Apr 1, 2025 · 0 comments
Open

json-server Converts Numeric "id" Fields to Strings #1636

RushiLee opened this issue Apr 1, 2025 · 0 comments

Comments

@RushiLee
Copy link

RushiLee commented Apr 1, 2025

Steps-
1.Create a JSON file (Ninja.json) with the following content
{
"Ninjas": [
{
"UID": 1,
"name": "Neji",
"courses": ["Maths", "Science"],
"ContactNum": 1111,
"Location": "Mumbai"
},
{
"UID": 2,
"name": "RockLee",
"courses": ["Magic", "Science"],
"ContactNum": 2222,
"Location": "Goa"
},
{
"UID": 3,
"name": "Garaa",
"courses": ["Geo", "Science"],
"ContactNum": 2222,
"Location": "Goa"
}
]
}

2.Start json-server with
json-server Ninja.json

3.Perform a GET request to http://localhost:3000/Ninjas

Expected Behavior
{
"Ninjas": [
{
"id": 1,
"name": "Neji",
"courses": ["Maths", "Science"],
"ContactNum": 1111,
"Location": "Mumbai"
},
{
"id": 2,
"name": "RockLee",
"courses": ["Magic", "Science"],
"ContactNum": 2222,
"Location": "Goa"
},
{
"id": 3,
"name": "Garaa",
"courses": ["Geo", "Science"],
"ContactNum": 2222,
"Location": "Goa"
},
{
"id": 4,
"name": "Naruto",
"courses": ["Hindi", "Maths"],
"ContactNum": 2222,
"Location": "Goa"
},
{
"id": 5,
"name": "Sasuke",
"courses": ["History", "Economics"],
"ContactNum": 2222,
"Location": "Goa"
}
]
}

Actual Behavior
[
{
"id": "1",
"name": "Neji",
"courses": [
"Maths",
"Science"
],
"ContactNum": 1111,
"Location": "Mumbai"
},
{
"id": "2",
"name": "RockLee",
"courses": [
"Magic",
"Science"
],
"ContactNum": 2222,
"Location": "Goa"
},
{
"id": "3",
"name": "Garaa",
"courses": [
"Geo",
"Science"
],
"ContactNum": 2222,
"Location": "Goa"
},
{
"id": "4",
"name": "Naruto",
"courses": [
"Hindi",
"Maths"
],
"ContactNum": 2222,
"Location": "Goa"
},
{
"id": "5",
"name": "Sasuke",
"courses": [
"History",
"Economics"
],
"ContactNum": 2222,
"Location": "Goa"
}
]

Workaround:
Changing id to a different field name (e.g., uid) prevents this behavior

Additional Details-
C:\Windows\System32>npm --version
10.9.2

C:\Windows\System32>node --version
v22.14.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant