Do you want JSON.stringify to keep dates intact ? The whole point is to turn it to a string.
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Do you want JSON.stringify to keep dates intact ? The whole point is to turn it to a string.
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
> Do you want JSON.stringify to keep dates intact ? The whole point is to turn it to a string.
There are ways to serialize data structures to strings. JSON doesn't generally do that, and it's been to its benefit as it helps keep it generic and easily usable from many languages.
That said, there are serialization tools which can correctly serialize and unserialize more complex structures, given the correct circumstances (only core constructs, or the objects in question have serialization helpers, or they are ensured to not have features that might cause problems such as references to outside data).
The point of this discussion is Javascript object cloning, not turning objects into a string. Offering up JSON and then responding to a criticism of it based on its methods as "the whole point is to turn it into a string" is somewhat ridiculous given many of the other options you're espousing JSON over don't use strings at all.
JSON.parse(JSON.stringify(obj)) !== deepClone(obj)
EDIT: Also, how can you determine if the string should be a date, or a string? Sure, if it fits, you can always convert it to a Date, but if your first object is coming from something that sends ISO Dates as strings and you used JSON.parse with a reviver, you would get a different object.