I saw the question about JSON data and I was reminded that I have seen a lot of people use
GetAsText() on different datatypes to push data into JSON.
Yes, JSON is text, and your data is not. But if your data is not already text then you don't want to use the
The built-in JSON tools allow you to specify exactly what sort of object it is. Half of the options describe structures, the other half describe what type of thing it is. The choices for data are: String, Number, Boolean.
If your data is in a container then you want
Base64EncodeRFC() to generate text from your binary data.
If your data isn't in a container, and it isn't already text, then you want to use
GetAsNumber() will transform dates, times, and timestamps into a number. Numbers transmit perfectly well in JSON. Both of the following forms will transmit the date in number format. The same is true for time fields, and timestamp fields.
JSONSetElement ( $json ; "date" ; GetAsNumber ( table::dateField ) ; JSONNumber )
JSONSetElement ( $json ; "date" ; GetAsNumber ( table::dateField ) ; 2 )
At the other end, all you have to do is to use the appropriate GetAs... function. Those functions will transform the number back into the date, time, or timestamp.
GetAsDate( JSONGetElement ( $json ; "date" ) )
GetAsTime( JSONGetElement ( $json ; "time" ) )
GetAsTimeStamp( JSONGetElement ( $json ; "timestamp" ) )
The nicest thing about using a number is that you don't have to jump through hoops to recreate the original data. No-one wants to parse string representations of timestamps. Simply use a number, and no one will ever have to, the original object is recreated perfectly without any fuss.