Re: TO JSON with dynamic array

Iwan AB <[email protected]> Tue, 30 Sep 2025 07:43:14 +0700
Newsgroups gmane.comp.lang.4gl.aubit.general
Message-ID <CAHJCSmLLgbHFp3JB7dW6ZzMVJpv3JB9xhyr2apbKemsjtY=0+Q@mail.gmail.com>
--===============7698411324294766106==
Content-Type: multipart/alternative; boundary="0000000000003d59b3063ffa0ae8"

--0000000000003d59b3063ffa0ae8
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Great. Thank you very much.
Btw, I've test the following code:

MAIN
   DEFINE  ws CHAR(200)
   DEFINE  wr RECORD
                 data ARRAY[5] OF CHAR(1)
              END RECORD

   LET ws =3D '{ "data": [ "a", "b", "c", "d", "e" ] }'
   LET FROM JSON wr.data =3D TO JSON(ws)

   DISPLAY "1=3D", wr.data[1]
   DISPLAY "2=3D", wr.data[2]
   DISPLAY "3=3D", wr.data[3]
   DISPLAY "4=3D", wr.data[4]
   DISPLAY "5=3D", wr.data[5]

END MAIN

the output is:
1=3D
2=3D
3=3D
4=3D
5=3D

instead of:
1=3Da
2=3Db
3=3Dc
4=3Dd
5=3De


On Tue, Sep 30, 2025 at 12:38=E2=80=AFAM Mike Aubury <[email protected]> wrote=
:

> Thats fixed in SVN now
>
> $ cat prog.4gl
> MAIN
>   DEFINE  wa DYNAMIC ARRAY OF RECORD
>                                  id CHAR(2),
>                                  product CHAR(60)
>                               END RECORD
>   DEFINE  i, n SMALLINT
>   DEFINE  w_json STRING
>
>   ALLOCATE ARRAY wa[10]
>
>
>   LET wa[1].id=3D1
>   LET wa[1].product=3D"Product 1"
>   LET wa[2].id=3D2
>   LET wa[2].product=3D"Product 2"
>   LET wa[3].id=3D3
>   LET wa[3].product=3D"Product 3"
>   LET wa[4].id=3D4
>   LET wa[4].product=3D"Product 4"
>
> display wa[1].id
> display wa[2].id
> display wa[3].id
> display wa[4].id
>
>   RESIZE ARRAY wa[4]
>
>   LET w_json =3D TO JSON(wa)
>   DISPLAY w_json
>
> END MAIN
>
> $ 4glpc -g prog.4gl -o prog.4ae
> $ ./prog.4ae
> 1
> 2
> 3
> 4
> [{"id":"1","product":"Product 1"},{"id":"2","product":"Product
> 2"},{"id":"3","product":"Product 3"},{"id":"4","product":"Product 4"}]
>
> On Mon, 29 Sept 2025 at 18:04, Iwan AB <[email protected]> wrote:
>
>> Dear Mike, I've tried the JSON operation. It is awesome, thank you. But
>> if I may suggest, it would be nice, if it could be implemented with DYNA=
MIC
>> ARRAY also.
>>
>> with static array:
>> MAIN
>>   DEFINE  wa ARRAY[5] OF RECORD
>>                           id CHAR(2),
>>                           product CHAR(60)
>>                          END RECORD
>>   DEFINE  i, n SMALLINT
>>   DEFINE  w_json STRING
>>
>>   DECLARE cur1 CURSOR FOR
>>      SELECT id, product FROM t1
>>
>>   LET i =3D 1
>>   FOREACH cur1 INTO wa[i].*
>>      LET i =3D i + 1
>>   END FOREACH
>>
>>   LET w_json =3D TO JSON(wa)
>>   DISPLAY w_json
>>
>> END MAIN
>>
>> OUTPUT:
>> [{"id": "1", "product": "P01"},{"id": "2", "product": "P02"},{"id": "3",
>> "product": "P03"}, {"id": "", "product": ""}, {"id":"", "product": ""}]
>>
>> with dynamic array:
>> MAIN
>>   DEFINE  wa DYNAMIC ARRAY OF RECORD
>>                                  id CHAR(2),
>>                                  product CHAR(60)
>>                               END RECORD
>>   DEFINE  i, n SMALLINT
>>   DEFINE  w_json STRING
>>
>>   ALLOCATE ARRAY wa[10]
>>
>>   DECLARE cur1 CURSOR FOR
>>      SELECT id, product FROM t1
>>
>>   LET i =3D 1
>>   FOREACH cur1 INTO wa[i].*
>>      LET i =3D i + 1
>>   END FOREACH
>>   LET n =3D i - 1
>>
>>   RESIZE ARRAY wa[n]
>>
>>   LET w_json =3D TO JSON(wa)
>>   DISPLAY w_json
>>
>> END MAIN
>>
>> OUTPUT
>> [{"id": "1", "product": "P01"},{"id": "1", "product": "P01"},{"id": "1",
>> "product": "P01"}]
>>
>> Regards,
>>
>> Iwan
>> _______________________________________________
>> Aubit4gl-discuss mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/aubit4gl-discuss
>>
>

--0000000000003d59b3063ffa0ae8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Great. Thank you very much.<div>Btw, I&#39;ve test the fol=
lowing code:</div><div><br></div><div>MAIN<br>=C2=A0 =C2=A0DEFINE =C2=A0ws =
CHAR(200)<br>=C2=A0 =C2=A0DEFINE =C2=A0wr RECORD<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0data ARRAY[5] OF CHAR(1)<br>=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 END RECORD<br><br>=C2=A0 =C2=A0L=
ET ws =3D &#39;{ &quot;data&quot;: [ &quot;a&quot;, &quot;b&quot;, &quot;c&=
quot;, &quot;d&quot;, &quot;e&quot; ] }&#39;<br>=C2=A0 =C2=A0LET FROM JSON =
wr.data =3D TO JSON(ws)<br><br>=C2=A0 =C2=A0DISPLAY &quot;1=3D&quot;, wr.da=
ta[1]<br>=C2=A0 =C2=A0DISPLAY &quot;2=3D&quot;, wr.data[2]<br>=C2=A0 =C2=A0=
DISPLAY &quot;3=3D&quot;, wr.data[3]<br>=C2=A0 =C2=A0DISPLAY &quot;4=3D&quo=
t;, wr.data[4]<br>=C2=A0 =C2=A0DISPLAY &quot;5=3D&quot;, wr.data[5]<br><br>=
END MAIN</div><div><br></div><div>the output is:</div><div>1=3D</div><div>2=
=3D</div><div>3=3D</div><div>4=3D</div><div>5=3D</div><div><br></div><div>i=
nstead of:</div><div><div>1=3Da</div><div>2=3Db</div><div>3=3Dc</div><div>4=
=3Dd</div><div>5=3De</div><div><br></div></div></div><br><div class=3D"gmai=
l_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Tue=
, Sep 30, 2025 at 12:38=E2=80=AFAM Mike Aubury &lt;<a href=3D"mailto:mike@a=
ubit.com">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail=
_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204=
,204);padding-left:1ex"><div dir=3D"ltr">Thats fixed in SVN now<div><br></d=
iv><div>$ cat prog.4gl<br>MAIN<br>=C2=A0 DEFINE =C2=A0wa DYNAMIC ARRAY OF R=
ECORD<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0id CHAR(2),<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0product CHAR(60)<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 END RECORD<br>=C2=A0 DEFINE =C2=A0i, n SMALLINT<br>=C2=A0 DEF=
INE =C2=A0w_json STRING<br><br>=C2=A0 ALLOCATE ARRAY wa[10]<br><br><br>=C2=
=A0 LET wa[1].id=3D1<br>=C2=A0 LET wa[1].product=3D&quot;Product 1&quot;<br=
>=C2=A0 LET wa[2].id=3D2<br>=C2=A0 LET wa[2].product=3D&quot;Product 2&quot=
;<br>=C2=A0 LET wa[3].id=3D3<br>=C2=A0 LET wa[3].product=3D&quot;Product 3&=
quot;<br>=C2=A0 LET wa[4].id=3D4<br>=C2=A0 LET wa[4].product=3D&quot;Produc=
t 4&quot;<br><br>display wa[1].id<br>display wa[2].id<br>display wa[3].id<b=
r>display wa[4].id<br><br>=C2=A0 RESIZE ARRAY wa[4]<br><br>=C2=A0 LET w_jso=
n =3D TO JSON(wa)<br>=C2=A0 DISPLAY w_json<br><br>END MAIN<br><br>$ 4glpc -=
g prog.4gl -o prog.4ae<br>$ ./prog.4ae<br>1<br>2<br>3<br>4<br>[{&quot;id&qu=
ot;:&quot;1&quot;,&quot;product&quot;:&quot;Product 1&quot;},{&quot;id&quot=
;:&quot;2&quot;,&quot;product&quot;:&quot;Product 2&quot;},{&quot;id&quot;:=
&quot;3&quot;,&quot;product&quot;:&quot;Product 3&quot;},{&quot;id&quot;:&q=
uot;4&quot;,&quot;product&quot;:&quot;Product 4&quot;}]<br></div></div><br>=
<div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, 29=
 Sept 2025 at 18:04, Iwan AB &lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"g=
mail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204=
,204,204);padding-left:1ex"><div dir=3D"ltr">Dear Mike, I&#39;ve tried the =
JSON operation. It is awesome, thank you. But if I may suggest, it would be=
 nice, if it could be implemented with DYNAMIC ARRAY also.<br><br>with stat=
ic array:<br>MAIN<br>=C2=A0 DEFINE =C2=A0wa ARRAY[5] OF RECORD<br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 id CHAR(2),<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 product CHAR(60)<br>=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0END RECORD<br>=C2=A0 DEFINE =C2=A0i, n SMALLINT<br>=C2=A0 DEFINE =C2=A0w=
_json STRING <br>=C2=A0 <br>=C2=A0 DECLARE cur1 CURSOR FOR<br>=C2=A0 =C2=A0=
 =C2=A0SELECT id, product FROM t1<br><br>=C2=A0 LET i =3D 1 =C2=A0 =C2=A0 <=
br>=C2=A0 FOREACH cur1 INTO wa[i].*<br>=C2=A0 =C2=A0 =C2=A0LET i =3D i + 1<=
br>=C2=A0 END FOREACH<br>=C2=A0 =C2=A0 <br>=C2=A0 LET w_json =3D TO JSON(wa=
)<br>=C2=A0 DISPLAY w_json<br><br>END MAIN<br><br>OUTPUT:<br>[{&quot;id&quo=
t;: &quot;1&quot;, &quot;product&quot;: &quot;P01&quot;},{&quot;id&quot;: &=
quot;2&quot;, &quot;product&quot;: &quot;P02&quot;},{&quot;id&quot;: &quot;=
3&quot;, &quot;product&quot;: &quot;P03&quot;}, {&quot;id&quot;: &quot;&quo=
t;, &quot;product&quot;: &quot;&quot;}, {&quot;id&quot;:&quot;&quot;, &quot=
;product&quot;: &quot;&quot;}] =C2=A0<br><br>with dynamic array:<br>MAIN<br=
>=C2=A0 DEFINE =C2=A0wa DYNAMIC ARRAY OF RECORD<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0id CHAR(2),<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0product CHAR(60)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 END RECORD<br>=C2=
=A0 DEFINE =C2=A0i, n SMALLINT<br>=C2=A0 DEFINE =C2=A0w_json STRING <br>=C2=
=A0 <br>=C2=A0 ALLOCATE ARRAY wa[10]<br>=C2=A0 <br>=C2=A0 DECLARE cur1 CURS=
OR FOR<br>=C2=A0 =C2=A0 =C2=A0SELECT id, product FROM t1<br><br>=C2=A0 LET =
i =3D 1 =C2=A0 =C2=A0 <br>=C2=A0 FOREACH cur1 INTO wa[i].*<br>=C2=A0 =C2=A0=
 =C2=A0LET i =3D i + 1<br>=C2=A0 END FOREACH<br>=C2=A0 LET n =3D i - 1<br>=
=C2=A0 <br>=C2=A0 RESIZE ARRAY wa[n]<br>=C2=A0 <br>=C2=A0 LET w_json =3D TO=
 JSON(wa)<br>=C2=A0 DISPLAY w_json<br><br>END MAIN<br><br>OUTPUT<br>[{&quot=
;id&quot;: &quot;1&quot;, &quot;product&quot;: &quot;P01&quot;},{&quot;id&q=
uot;: &quot;1&quot;, &quot;product&quot;: &quot;P01&quot;},{&quot;id&quot;:=
 &quot;1&quot;, &quot;product&quot;: &quot;P01&quot;}]<div><br></div><div>R=
egards,</div><div><br></div><div>Iwan</div></div>
_______________________________________________<br>
Aubit4gl-discuss mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank"=
>[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/aubit4gl-discuss" r=
el=3D"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/lis=
tinfo/aubit4gl-discuss</a><br>
</blockquote></div>
</blockquote></div>

--0000000000003d59b3063ffa0ae8--


--===============7698411324294766106==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============7698411324294766106==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Aubit4gl-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/aubit4gl-discuss

--===============7698411324294766106==--