I wonder if anyone thought about custom data types e.g. ISO8601

40 views
Skip to first unread message

mofo syne

unread,
Oct 8, 2015, 9:01:49 AM10/8/15
to JSON5
{"data": !ISO8601 "2013-10-07T18:06:03.048Z"}

Above is how yaml would approach this. Obviously not JSON compatible.

Below is how MongelDB approches it:

{"data":{"$date":"2013-10-07T18:06:03.048Z"}}

-------

Would be interesting to see if there is a way to define custom datatypes in a way that is consistent with javascript V5.





mofo syne

unread,
Oct 8, 2015, 9:02:57 AM10/8/15
to JSON5
Btw, a clean consistent custom datatype could help with adoption of json5,

Jordan Tucker

unread,
Oct 8, 2015, 1:04:12 PM10/8/15
to JSON5
The issues with implementing native Date support have been discussed on the GitHub issue where shish's comment sums it up quite nicely.

storing as strings and then attempting to turn all strings into dates would have false positives; storing as non-strings breaks the purity of the format

Also, YAML's method would violate one of the core values:

JSON5 remains a strict subset of JavaScript

Probably the best solution would be to allow new Date() or Date.parse() as values. When JSON5 is serialized as JSON, it would output the date string, but when serialized as JSON5, it would output new Date() or Date.parse().

BTW, new Date() and Date.parse() are equivalent, so it comes down to which ones feels better. I think my vote is for new Date() since it's two characters less.

I'm going to copy this info onto the GitHub issue, so please continue discussion there. Thanks.
Reply all
Reply to author
Forward
0 new messages