Hello.
I came across something nice today. Whether it's intentional or not I don't know, and maybe Scott Klement can chime in since I'm using his YAJLDTAGEN.
Using a varying dimension array (DIM(*AUTO) I found that DATA-GEN will serialize based on the number of array entries actually used, thereby eliminating the need for using "countprefix".
Here's code:
The result is variable "jsonDoc" contains [{"name":"John"},{"name":"Doe"}]. No need for an additonal field (like num_names).
If I take out *AUTO so that it's just a DIM(10) then I get an additional eight empty names.
Pretty cool, if it's by design.
I couldn't find any documentation about this in the ILE RPG Reference but found this in Open Access guide for RPG (subfield totalElems looks like the key):
Any thoughts?
Mike
I came across something nice today. Whether it's intentional or not I don't know, and maybe Scott Klement can chime in since I'm using his YAJLDTAGEN.
Using a varying dimension array (DIM(*AUTO) I found that DATA-GEN will serialize based on the number of array entries actually used, thereby eliminating the need for using "countprefix".
Here's code:
Code:
h dftactgrp(*no) option(*srcstmt: *nodebugio: *noshowcpy) h bnddir('YAJL/YAJL') h decedit('0.') dcl-s jsonDoc varchar(250); dcl-ds names dim(*auto: 10) qualified inz; name varchar(50); end-ds; names(*next).name = 'John'; names(*next).name = 'Doe'; data-gen names %data(jsonDoc) %gen('YAJL/YAJLDTAGEN'); *inlr = *on; return;
If I take out *AUTO so that it's just a DIM(10) then I get an additional eight empty names.
Pretty cool, if it's by design.
I couldn't find any documentation about this in the ILE RPG Reference but found this in Open Access guide for RPG (subfield totalElems looks like the key):
Any thoughts?
Mike
Comment