Every day a lot of developers re-invent work-arounds for the fact that JSON is missing
some basic data structures: Datetime, Timedelta and Binary Data Types
I know this can't be fixed in one year. This will take several years.
And JSON isn't even part of ECMAScript, but an entirely different spec complete with an RFC. It's just an interchange format whose syntax was inspired by ES3.
You might have better luck elsewhere, and if you want anything changed, you'll need to contact a lot of different people and get several companies interested. Also, do expect resistance - part of the allure of JSON is because of its simplicity, and there's a lot of tooling built on it that would have to change.
I think it should be possible to make binary, datetime, timedelta optional available. Tools should only need to update if the want to use the new features.
unlike c# and other languages, a datetime datatype in javascript doesn't add much value, because in practice, javascript-programmers offload most datetime-logic to external databases (or [client-side] wasm-sqlite3).
the remaining scenarios in javascript-land are mostly i/o -- message-passing isostrings over-the-wire between UI's <-> datastores.
yes, temporals are commonly created by parsing from isostrings:
var json = {
"isostring": "2019-11-26T14:58:54.147Z"
};
var datetime = Temporal.DateTime.from(json.isostring);
what you'll find in practice is that isostrings (e.g. "2019-11-26T14:58:54.147Z") are sufficient for representing datetime in JSON, and there no need to complicate it with an additional datetime datatype.
I would like to be able to load a json string. And the data structure in the language js/python/... should be highlevel data structure. This should happen without any additional step like parsing strings or base64-decoding.
The issue is that dates and times are complicated, and simplifying them runs the risk of losing way too much information. They sound much simpler than they are:
Times could be local or have a time zone, and that's not even counting leap seconds. You can't even measure the number of seconds between two instants without reading the tzdb first.
Date manipulation depends on leap years (which are themselves non-trivial), and this is only assuming the civil Gregorian calendar - astronomers usually use Julian years (defined as exactly 365.25 days of 86400 SI seconds) in their calculations, and religions like Islam have their own calendars (in that case, the Islamic calendar, based on the moon rather than the sun), and so while the temporal proposal strictly focuses on the Gregorian calendar, most larger date manipulation libraries include support for other calendars like those.
Combine the two, and it gets even more complicated. You've got time zones (some are even like UTC+4:30), you've got daylight savings (you can't even assume this is an hour forward), you've got various governments passing laws changing either or both of these at any moment, you've got all the abbreviations like "EST" for Eastern Standard Time and "UTC" for Universal Coordinated Time, and it all gets super messy.
Separately, JSON does not have any sort of date, time, or date-time syntax, and never has. The usual way of handling it is serializing it as ISO-8601 (what you get out of Date.prototype.toJSON and Date.prototype.toISOString and deserializing it accordingly.
Yes, you are right. Serializing and parsing dates is complicated. But it was already solved several times and there are specs for it. I would never ever reinvent this. This is already solved.
Yes, JavaScript does not have any sort of date, time (up to now).
Just FYI: this is most likely dead on arrival. I tried as little as just trying to get comments in, and even that wound up proving near impossible to get anywhere.
I like the simplicity of JSON. I don't think it's practical to try and incorporate a bunch of special-purpose data-structures into the spec. If we add support for Date, then someone will want support for a set data structure (it deserializes into the languages native set data-structure). If we add support for that, then someone will want to add support for enums.
And, what happens when the target language doesn't have a concept of a set, or an enum, or a timespan, or whatever feature we're wanting to add to JSON? As JSON is supposed to be language agnostic, I think it's important that we keep its feature set down to a minimum, because:
It makes it easier for any language to add good support for it.
It keeps parsers simple, letting this get used on, for example, IOT devices
It keeps the spec more stable, we're not trying to always add new features to it, causing everyone to have to update their parsers