Re: TO JSON with dynamic array
Mike Aubury <[email protected]> Mon, 29 Sep 2025 18:37:55 +0100
| Newsgroups | gmane.comp.lang.4gl.aubit.general |
|---|---|
| Message-ID | <CAGAq4WGzRThaQj=CR3GLfJRThbzqRzJKenVmM7uBi6UW7Zr3zQ@mail.gmail.com> |
--===============2067230197418177845==
Content-Type: multipart/alternative; boundary="0000000000001bc6e4063ff4193e"
--0000000000001bc6e4063ff4193e
Content-Type: text/plain; charset="UTF-8"
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=1
LET wa[1].product="Product 1"
LET wa[2].id=2
LET wa[2].product="Product 2"
LET wa[3].id=3
LET wa[3].product="Product 3"
LET wa[4].id=4
LET wa[4].product="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 = 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 DYNAMIC
> 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 = 1
> FOREACH cur1 INTO wa[i].*
> LET i = i + 1
> END FOREACH
>
> LET w_json = 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 = 1
> FOREACH cur1 INTO wa[i].*
> LET i = i + 1
> END FOREACH
> LET n = i - 1
>
> RESIZE ARRAY wa[n]
>
> LET w_json = 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
>
--0000000000001bc6e4063ff4193e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Thats fixed in SVN now<div><br></div><div>$ cat prog.4gl<b=
r>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 RECO=
RD<br>=C2=A0 DEFINE =C2=A0i, n SMALLINT<br>=C2=A0 DEFINE =C2=A0w_json STRIN=
G<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"Product 1"<br>=C2=A0 LET wa[2].id=3D=
2<br>=C2=A0 LET wa[2].product=3D"Product 2"<br>=C2=A0 LET wa[3].i=
d=3D3<br>=C2=A0 LET wa[3].product=3D"Product 3"<br>=C2=A0 LET wa[=
4].id=3D4<br>=C2=A0 LET wa[4].product=3D"Product 4"<br><br>displa=
y wa[1].id<br>display wa[2].id<br>display wa[3].id<br>display wa[4].id<br><=
br>=C2=A0 RESIZE ARRAY wa[4]<br><br>=C2=A0 LET w_json =3D TO JSON(wa)<br>=
=C2=A0 DISPLAY w_json<br><br>END MAIN<br><br>$ 4glpc -g prog.4gl -o prog.4a=
e<br>$ ./prog.4ae<br>1<br>2<br>3<br>4<br>[{"id":"1",&qu=
ot;product":"Product 1"},{"id":"2","=
;product":"Product 2"},{"id":"3","p=
roduct":"Product 3"},{"id":"4","pro=
duct":"Product 4"}]<br></div></div><br><div class=3D"gmail_q=
uote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, 2=
9 Sept 2025 at 18:04, Iwan AB <<a href=3D"mailto:[email protected]">iw87c=
[email protected]</a>> 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">Dear Mike, I've tried the JSON operation. I=
t is awesome, thank you. But if I may suggest, it would be nice, if it coul=
d be implemented with DYNAMIC ARRAY also.<br><br>with static 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 FOREAC=
H cur1 INTO wa[i].*<br>=C2=A0 =C2=A0 =C2=A0LET i =3D i + 1<br>=C2=A0 END FO=
REACH<br>=C2=A0 =C2=A0 <br>=C2=A0 LET w_json =3D TO JSON(wa)<br>=C2=A0 DISP=
LAY w_json<br><br>END MAIN<br><br>OUTPUT:<br>[{"id": "1"=
;, "product": "P01"},{"id": "2", &q=
uot;product": "P02"},{"id": "3", "p=
roduct": "P03"}, {"id": "", "produc=
t": ""}, {"id":"", "product": =
""}] =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 C=
HAR(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 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 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)<b=
r>=C2=A0 DISPLAY w_json<br><br>END MAIN<br><br>OUTPUT<br>[{"id": =
"1", "product": "P01"},{"id": "=
;1", "product": "P01"},{"id": "1&qu=
ot;, "product": "P01"}]<div><br></div><div>Regards,</di=
v><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>
--0000000000001bc6e4063ff4193e--
--===============2067230197418177845==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============2067230197418177845==
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
--===============2067230197418177845==--