Description
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