I have a pretty flat JSON which can have an attribute more than once. After I've built some logic to kick out the 'old' values, I wanted to try it out of course. Then I discovered something really strange. My logic always counted the attributes once which meant there are no duplicates. So I went ahead and created this dummy JSON:
{
"John": {
"id": 10001,
"name": "John Doe",
"iconId": 10,
"level": 12,
"revisionDate": 1000000000001
},
"John": {
"id": 10001,
"name": "John Doe",
"iconId": 10,
"level": 12,
"revisionDate": 1000000000005
},
"Amy": {
"id": 10002,
"name": "Amy Smith",
"iconId": 15,
"level": 11,
"revisionDate": 1000000000001
}
}
As you can see the duplicate here is John. The only difference is his revision date.
Now I load up the JSON in NodeJS and log it like this:
// loading JSON
let oldResults = require('./dummy.json');
// log JSON
console.log(oldResults);
At this point the strange thing happens. My console will show me the second John in my JSON and Amy, but never the first John:
λ node debug.js
{ John:
{ id: 10001,
name: 'John Doe',
iconId: 10,
level: 12,
revisionDate: 1000000000005 },
Amy:
{ id: 10002,
name: 'Amy Smith',
iconId: 15,
level: 11,
revisionDate: 1000000000001 } }
If I change the second John to John123 the first one will be logged as the others (doesn't matter If I change the first or the second, the results will be the same):
λ node debug.js
{ John:
{ id: 10001,
name: 'John Doe',
iconId: 10,
level: 12,
revisionDate: 1000000000001 },
John123:
{ id: 10001,
name: 'John Doe',
iconId: 10,
level: 12,
revisionDate: 1000000000005 },
Amy:
{ id: 10002,
name: 'Amy Smith',
iconId: 15,
level: 11,
revisionDate: 1000000000001 } }
I've tried this with the normal Windows CMD and CMDER. Both show me the same result. Also I cleared the node cache, still no success... I load this JSON in my debug.js with no other logic, which could alter the JSON.
Can someone please explain me why NodeJS is kicking out the second John?
Regards, Megajin