On Fri, 01 Apr 2011, Ron Pinkas wrote:

Hi Ron,

> >JSON format does not support dates and timestamp values.
> >So when you pass date item to be converted to JSON format
> >we have 3 choices:
> >1. generate RTE
> >2. convert date to some other format, accepted by JSON, i.e.
> >  "YYYYMMDD" strings
> >3. store it as NIL/NULL value.
> We could also consider a 4th choice, I.e. when converting date to
> string in the wrapper add extra flag to the string such that when it
> is decoded the wrapper will again convert the JSON decoded string to
> a date value. This of course means that the string coded by JSON
> will read something like:
>   {DATE}YYYYMMDD
> and it will therefore not be usable by other JSON decoders unless
> they expect such convention.

This is not such simple. It cannot be implemented cleanly.
JSON is very strict format. Adding rule to deserialize procedure
that strings in format:
   [{]DATE[}][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
are decoded as dates causes that it's not possible to pass such
string because it will be converted to date during decoding, i.e.
it's not possible to divide this message into words in an array and
then encode and decode it using such hacked JSON decode algorithm.
The result will be different then the source though source contains
perfectly valid JSON data. So adding such hack to handle date values
which are unsupported by JSON breaks decoding supported data.
The only one way to handle new types automatically is adding some
new type to JSON format which will not interact with existing ones.
Anyhow JSON is very simple format for validators and it's very easy
to write simple state machine which will be perfectly restrictive in
format checking so you should expect that any "local" extensions will
be detected immediately by foreign systems and decoding refused.
This is one of the most important JSON features which makes it popular
to exchange data between different systems. It has only small set of
supported data types stored in very simple format which can be easy
validated by decoding procedure so any local hacks or bugs in
implementation are easy to detect.
BTW Mindaugas didn't implement such state machine but only simple
decoding algorithm which assumes that input data is correct. It's
acceptable though state machine could also improve decoding speed
so we may thing about adding it in the future.

best regards,
Przemek

------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
xHarbour-developers mailing list
xHarbour-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xharbour-developers

Reply via email to