logoalt Hacker News

flyingmeteoryesterday at 5:21 PM3 repliesview on HN

You would need to use the `reviver` parameter of `JSON.parse()` to revive your date strings to Temporal objects. As others have said, it's a simple `Temporal.from()`

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


Replies

foresterretoday at 12:33 AM

Depending on your needs (i.e. how you would otherwise use your output jspn), using the reviver can have a significant impact on performance. JSON.parse itself is hyper-optimized. At the company I work we used the reviver for almost exactly this, but profiling showed that using the reviver had enormous impact on performance. We cut it out, and won in the seconds of performance for some large json's.

cyralyesterday at 5:35 PM

I've been doing this for so long and never knew there was a reviver param, thanks - that is super useful.

Bratmonyesterday at 6:38 PM

Having to provide a complete schema of your json everywhere your json gets parsed negates the advantages of json.

show 2 replies