JSON has no date type, so a date goes out as a Date and comes back as a string. Then some line calls getTime on it and falls over.
JSON.parse takes a second argument that sees every key and value:
const text = '{"createdAt":"2026-11-30T09:00:00Z","name":"x"}';
const data = JSON.parse(text, (key, value) =>
key.endsWith('At') && typeof value === 'string'
? new Date(value)
: value
);
console.log(data.createdAt.getFullYear());
Whatever the function returns replaces the value. Here every key ending in At becomes a Date, at any depth, and the rest passes through untouched.
Always return value for things you do not change. Forget it and the property is removed, which is the classic mistake with revivers: you end up with undefined as the whole result.
I decide by key name on purpose. Guessing from the content would also convert a product code or a title that happens to look like a date. A string that cannot be parsed becomes an invalid date without throwing, so check input you do not control.
Further reading: MDN: JSON.parse()