For anyone still following along with this (and for the archives), I joined
Arnaud on the forums and got in trouble ;-) I also made a few feature
requests:

New command: JSON Stringify stored array
http://forums.4d.fr/Post//18931320/1/

OB Get Array 4D type
http://forums.4d.fr/Post//18931295/1/

OB GET PROPERTY NAMES enhancement
http://forums.4d.fr/Post//18931215/1/

I'm also cross-posting (mea culpa) so code for anyone interested in the way
4D coerces arrays of different types out of a C_OBJECT area. It's really
dumb code. This is from V16.0 in a brand new database. The results appear
the same interpreted and compiled It lets you see what you get for the
supported types apart from pointers. I haven't tried pointers via objects
yet so I left them out. If anyone feels like updating the code, I'd be
happy to see the results. Sorry, I don't know the names of the commands in
French, this is just code in English.

ARRAY BOOLEAN(boolean_array_in;0)
APPEND TO ARRAY(boolean_array_in;True)
APPEND TO ARRAY(boolean_array_in;False)
APPEND TO ARRAY(boolean_array_in;True)

ARRAY REAL(real_array_in;0)
APPEND TO ARRAY(real_array_in;1.1)
APPEND TO ARRAY(real_array_in;2.2)
APPEND TO ARRAY(real_array_in;3.3)

ARRAY TEXT(text_array_in;0)
APPEND TO ARRAY(text_array_in;"monday")
APPEND TO ARRAY(text_array_in;"tuesday")
APPEND TO ARRAY(text_array_in;"wednesday")

ARRAY OBJECT(object_array_in;0)
C_OBJECT($empty_object)

C_OBJECT($simple_object)
$simple_object:=JSON Parse("{}")

C_OBJECT($object_with_a_few_elements)
$object_with_a_few_elements:=JSON Parse("{}")
OB SET($object_with_a_few_elements;"Number";Pi)
OB SET($object_with_a_few_elements;"Text";"Hello world!")
OB SET($object_with_a_few_elements;"Boolean";True)

APPEND TO ARRAY(object_array_in;$empty_object)
APPEND TO ARRAY(object_array_in;$simple_object)
APPEND TO ARRAY(object_array_in;$object_with_a_few_elements)

C_OBJECT(object)
object:=JSON Parse("{}")
OB SET ARRAY(object;"boolean_array_in";boolean_array_in)
OB SET ARRAY(object;"real_array_in";real_array_in)
OB SET ARRAY(object;"text_array_in";text_array_in)
OB SET ARRAY(object;"object_array_in";object_array_in)

C_TEXT($cr)
$cr:=Char(Carriage return)

C_TEXT($dump_text)
$dump_text:=""
$dump_text:=$dump_text+"JSON Stringify of complete object."
$dump_text:=$dump_text+$cr

C_TEXT($json)
$dump_text:=$dump_text+JSON Stringify(object;*)+$cr+$cr
$dump_text:=$dump_text+$cr

$dump_text:=$dump_text+"----------------------------------------------------------"+$cr
$dump_text:=$dump_text+"Pull each type out into a Boolean array"+$cr
$dump_text:=$dump_text+"----------------------------------------------------------"+$cr

ARRAY BOOLEAN(boolean_array_out;0)
ARRAY REAL(real_array_out;0)
ARRAY TEXT(text_array_out;0)
ARRAY OBJECT(object_array_out;0)

OB GET ARRAY(object;"boolean_array_in";boolean_array_out)
OB GET ARRAY(object;"boolean_array_in";real_array_out)
OB GET ARRAY(object;"boolean_array_in";text_array_out)
OB GET ARRAY(object;"boolean_array_in";object_array_out)

$dump_text:=$dump_text+"Source array boolean_array_in"+$cr
$dump_text:=$dump_text+JSON Stringify array(boolean_array_in)+$cr+$cr

$dump_text:=$dump_text+"Output array boolean_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(boolean_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array real_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(real_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array text_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(text_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array object_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(object_array_out)+$cr+$cr

$dump_text:=$dump_text+"----------------------------------------------------------"+$cr
$dump_text:=$dump_text+"Pull each type out into a Real array"+$cr
$dump_text:=$dump_text+"----------------------------------------------------------"+$cr

ARRAY BOOLEAN(boolean_array_out;0)
ARRAY REAL(real_array_out;0)
ARRAY TEXT(text_array_out;0)
ARRAY OBJECT(object_array_out;0)

OB GET ARRAY(object;"real_array_in";boolean_array_out)
OB GET ARRAY(object;"real_array_in";real_array_out)
OB GET ARRAY(object;"real_array_in";text_array_out)
OB GET ARRAY(object;"real_array_in";object_array_out)

$dump_text:=$dump_text+"Source array real_array_in"+$cr
$dump_text:=$dump_text+JSON Stringify array(real_array_in)+$cr+$cr

$dump_text:=$dump_text+"Output array boolean_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(boolean_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array real_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(real_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array text_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(text_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array object_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(object_array_out)+$cr+$cr

$dump_text:=$dump_text+"----------------------------------------------------------"+$cr
$dump_text:=$dump_text+"Pull each type out into a Text array"+$cr
$dump_text:=$dump_text+"----------------------------------------------------------"+$cr

ARRAY BOOLEAN(boolean_array_out;0)
ARRAY REAL(real_array_out;0)
ARRAY TEXT(text_array_out;0)
ARRAY OBJECT(object_array_out;0)

OB GET ARRAY(object;"text_array_in";boolean_array_out)
OB GET ARRAY(object;"text_array_in";real_array_out)
OB GET ARRAY(object;"text_array_in";text_array_out)
OB GET ARRAY(object;"text_array_in";object_array_out)

$dump_text:=$dump_text+"Source array text_array_in"+$cr
$dump_text:=$dump_text+JSON Stringify array(text_array_in)+$cr+$cr

$dump_text:=$dump_text+"Output array boolean_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(boolean_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array real_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(real_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array text_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(text_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array object_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(object_array_out)+$cr+$cr

$dump_text:=$dump_text+"----------------------------------------------------------"+$cr
$dump_text:=$dump_text+"Pull each type out into a Object array"+$cr
$dump_text:=$dump_text+"----------------------------------------------------------"+$cr

ARRAY BOOLEAN(boolean_array_out;0)
ARRAY REAL(real_array_out;0)
ARRAY TEXT(text_array_out;0)
ARRAY OBJECT(object_array_out;0)

OB GET ARRAY(object;"object_array_in";boolean_array_out)
OB GET ARRAY(object;"object_array_in";real_array_out)
OB GET ARRAY(object;"object_array_in";text_array_out)
OB GET ARRAY(object;"object_array_in";object_array_out)

$dump_text:=$dump_text+"Source array object_array_in"+$cr
$dump_text:=$dump_text+JSON Stringify array(object_array_in)+$cr+$cr

$dump_text:=$dump_text+"Output array boolean_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(boolean_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array real_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(real_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array text_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(text_array_out)+$cr+$cr

$dump_text:=$dump_text+"Output array object_array_out"+$cr
$dump_text:=$dump_text+JSON Stringify array(object_array_out)+$cr+$cr

SET TEXT TO PASTEBOARD($dump_text)
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to