Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Aha yes you are correct - it outputs an ISO string at the very least but does not parse it back to a date. I will update the article to reflect this!


Ok but please read carefuly because JSON.parse can in fact recover dates. The JSON.parse function accepts a 'reviver' function as an argument to do just that. 99% of the time it's not useful so there is no reason for JSON.parse to do it by default but JSON.parse definitely can parse dates back if you use all it's features.

I like that it does not do it by default but I can make it parse the dates if I want.


Saying that JSON.parse can do something when it's really just you implementing the transformation from string to date object is a little misleading.

You can make JSON parse arbitrary sublanguages if you're willing to put in the work.


And what do you pass as the reviver argument? Your own function to check a string to see if it's valid IS8601 and parse it? That's just using parse()'s recursive walking of the object: it does no date reviving itself, right?


That way you can get different result, as you could actually have date object and date as string stored somewhere. You will need custom strigify callback to differentiate which should be converted back to date on parse and which should be a string.

Still, this is not pure json this way, it's your own transformations




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: