# JSON: Add Datetime, Timedelta and Binary Data Types

**URL:** <https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134>\
**Category:** 💡 Ideas\
**Created:** [November 21, 2019, 9:39am UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134 "2019-11-21T09:39:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![guettli](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/guettli/32/203_2.png) [@guettli](https://es.discourse.group/u/guettli)\
**Post date:** [November 21, 2019, 9:39am UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/1 "2019-11-21T09:39:49Z")

</div>

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.

How to start this journey?

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [November 21, 2019, 7:48pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/2 "2019-11-21T19:48:00Z")

</div>

2 of those 3 data types you mentioned aren't things in JavaScript.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [November 21, 2019, 8:22pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/3 "2019-11-21T20:22:51Z")

</div>

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.

- [ECMA-404 2nd Edition](https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf)
- [RFC 8259](https://tools.ietf.org/html/rfc8259)
- The ES spec itself changed to make it a superset of JSON: [https://github.com/tc39/proposal-json-superset](https://github.com/tc39/proposal-json-superset)

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.

---

<div class="post-metadata">

**Author:** ![guettli](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/guettli/32/203_2.png) [@guettli](https://es.discourse.group/u/guettli)\
**Post date:** [November 22, 2019, 10:40am UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/4 "2019-11-22T10:40:01Z")

</div>

Thank you for pointing me in the right direction.

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.

---

<div class="post-metadata">

**Author:** ![kaizhu256](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kaizhu256/32/342_2.png) [@kaizhu256](https://es.discourse.group/u/kaizhu256)\
**Post date:** [November 25, 2019, 4:28pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/5 "2019-11-25T16:28:51Z")

</div>

as a bit of resistance:

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.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [November 25, 2019, 6:34pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/6 "2019-11-25T18:34:02Z")

</div>

The Temporal proposal will likely change this practice, however.

---

<div class="post-metadata">

**Author:** ![guettli](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/guettli/32/203_2.png) [@guettli](https://es.discourse.group/u/guettli)\
**Post date:** [November 26, 2019, 8:45am UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/7 "2019-11-26T08:45:47Z")

</div>

Quoting Wikipedia: "JSON is a language-independent data format."

Python supports binary, datetime, timedelta and many other languages, too.

Why not create smooth transition with optional support for more data types? I see no drawback.

A lot of specs get continous upgrades (tcp, http, ...) why not JSON?

---

<div class="post-metadata">

**Author:** ![guettli](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/guettli/32/203_2.png) [@guettli](https://es.discourse.group/u/guettli)\
**Post date:** [November 26, 2019, 8:57am UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/8 "2019-11-26T08:57:10Z")

</div>

Is there already a common way to parse a string to a temporal object?

I started a little page to gather notes. I would like to add a early sketch how datetime could get serialized in JSON.

Here are the early notes: [https://github.com/guettli/lets-fix-json/blob/master/README.md](https://github.com/guettli/lets-fix-json/blob/master/README.md)

---

<div class="post-metadata">

**Author:** ![kaizhu256](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kaizhu256/32/342_2.png) [@kaizhu256](https://es.discourse.group/u/kaizhu256)\
**Post date:** [November 26, 2019, 3:09pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/9 "2019-11-26T15:09:43Z")

</div>

yes, temporals are commonly created by parsing from isostrings:

```javascript
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.

---

<div class="post-metadata">

**Author:** ![guettli](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/guettli/32/203_2.png) [@guettli](https://es.discourse.group/u/guettli)\
**Post date:** [November 26, 2019, 3:48pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/10 "2019-11-26T15:48:32Z")

</div>

I want it simpler, not more complicated.

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.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [December 20, 2019, 12:03am UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/11 "2019-12-20T00:03:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![guettli](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/guettli/32/203_2.png) [@guettli](https://es.discourse.group/u/guettli)\
**Post date:** [December 20, 2019, 11:51am UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/12 "2019-12-20T11:51:17Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![ExtAnimal](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/extanimal/32/1153_2.png) [@ExtAnimal](https://es.discourse.group/u/ExtAnimal)\
**Post date:** [December 12, 2021, 4:15pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/13 "2021-12-12T16:15:27Z")

</div>

I’ve been wanting something like this for ages.

A way now writing Date literal without using new Date. So dates (and time deltas) can be transmitted and read easily.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [December 12, 2021, 4:59pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/14 "2021-12-12T16:59:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [December 12, 2021, 6:23pm UTC](https://es.discourse.group/t/json-add-datetime-timedelta-and-binary-data-types/134/15 "2021-12-12T18:23:30Z")

</div>

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
