|
|
|
|
|
by dspillett
1130 days ago
|
|
Type validation for one. The reduced chance that a client has put some backwards format in there like MM-DD-YYYY (or DD-MM-YYYY for that matter) or just an invalid date completely. You might as well ask what native numeric or boolean support offer over just jamming stuff in a string in an agreed format. Some might argue that dates are a compound value so differ from atomic types like a number, but they are wrong IMO as a datetime can be treated as a simple numeric¹ with the compound display being just that – a display issue. Others will point out that JS doesn't have a native date/datetime/time type, but JSON is used for a lot more that persisting JS structures at this point. -- [1] caveat: this stops being true if you have a time portion with a timezone property |
|
A big difference is that a numeric or a boolean are quite limited datatypes with agreed upon semantics (mostly).
> Others will point out that JS doesn't have a native date/datetime/time type
It does, in fact. And it's absolute shit.
> but JSON is used for a lot more that persisting JS structures at this point.
So what I'm reading here is that you don't need types to be supported natively in order to serialize to JSON.