× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Not sure what the heck YAGL is Darryl - did you mean YAJL?

Most people use Scott's generator. Where did you get this one?

Regardless, you need to use countprefix to correctly output arrays. By "correctly", I mean only outputting the number of elements that have been filled. BUT outputting empty elements should not cause a crash, regardless.

As always, it would be helpful if you had actually included a sample of the DS and Data-Gen you are using.

This is roughly what it should look like.

Dcl-ds Invoice Qualified Inz;
CustomerId char(6);
Invoice_Number int(10);
count_Invoice_Detail int(5);
Dcl-ds Invoice_Detail Dim(20);
Item char(10);
Quantity int(5);
...
End-ds;
End-ds;

Then the DG would include this:

%Data( json : 'doc=file countprefix=count_ ')


Be aware, though that this may not answer all of your problems. If I recall correctly, one of the issues with DG is that it will output an empty array when the count is zero.

e.g. if count_Invoice_Detail = zero the output would include:

... { "Invoice_Detail" : [ ] } or something like that.

You can see an example that uses countprefix for an optional field in this article https://www.itjungle.com/2021/07/12/guru-web-services-data-into-and-data-gen-part-3/.

For documents that include optional blocks, you will need to use DG's *Start and *End options and output the json in pieces.

Alternatively, for highly complex documents with a lot of optional "bits", you may need to use the raw APIs in YAJL.



Jon Paris
Jon.Paris@xxxxxxxxxxxxxx



On Sep 11, 2025, at 8:30 PM, <dfreinkel@xxxxxxxxxxxxxxxxx> <dfreinkel@xxxxxxxxxxxxxxxxx> wrote:

No, I did not see parameters for those.

Darryl Freinkel

--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.