Using DATA-GEN + YAJLDTAGEN for iterative build

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
Post Reply
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Using DATA-GEN + YAJLDTAGEN for iterative build

Post by jonboy49 »

I know I could do this by simply nesting the structures, but I am trying to use the iterative build feature for cases where the array size exceeds RPG's capabilities. Problem is no matter how I try to structure it the resulting JSON is always "close but no cigar". I have these two DS;

Code: Select all

Dcl-ds  orderHeader  Inz;
   CustomerName     varchar(40);
   CustomerId       char(6);
   name_PO_Number   char(9) inz('PO Number');
   PO_Number        varchar(20);
   DueDate          date(*USA);
End-ds;


Dcl-ds  detailLine;
  itemCode  char(8);
  quantity  int(5);
  price     packed(5:2);
End-ds;
And what I want to produce is something like this:

Code: Select all

{
    "CustomerName": "",
    "CustomerId": "",
    "PO Number": "",
    "DueDate": "03/30/2022",
    "Details": [
        {
            "itemCode": "Item-1",
            "quantity": 1,
            "price": 0.60
        },
        repeat items ad naseum
    ]
}
No matter what combo of DATA-GEN I try the best I can get so far is this:

Code: Select all

{
    "CustomerName": "",
    "CustomerId": "",
    "PO Number": "",
    "DueDate": "03/30/2022"
}  <<< this close not wanted ...
[  <<< this array needs a key
    {
        "itemCode": "Item-1",
        "quantity": 1,
        "price": 0.60
I'm guessing that between YAJLDTAGEN and DATA-GEN there is not a combination that will work. Is there any kind of JSON document that can be built iteratively ? I can't think of anything right now but since I know Scott would have tested the capability I feel I am just missing something.
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: Using DATA-GEN + YAJLDTAGEN for iterative build

Post by Scott Klement »

Unfortunately, there really isn't a way to do that.

DATA-GEN passes an RPG variable, and YAJLDTAGEN converts that variable to JSON format.

If you think about what you're trying to output -- you're trying to output "part of" a variable. The top of your document is this:

Code: Select all

{               <-- this is a "data structure"
    "CustomerName": "",
    "CustomerId": "",
    "PO Number": "",
    "DueDate": "03/30/2022",
    "Details": [ <-- this is an array
So you are asking DATA-GEN to pass just "part of" a data structure, and part of an array. This just isn't how DATA-GEN works, it always passes an entire variable.

Using the YAJL subprocedures you could do it easily.
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: Using DATA-GEN + YAJLDTAGEN for iterative build

Post by jonboy49 »

So effectively the iterative build option is just not usable with YAJLDTAGEN at all then? Or can you think of a case that works?
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: Using DATA-GEN + YAJLDTAGEN for iterative build

Post by Scott Klement »

There are two different things I can think of that might be referred to as an "interative build". I'm assuming you mean sequences where you do *START and *END, right?

You can use sequences with YAJLDTAGEN provided that the top-level element is an array or an object, and that each sub-element is added directly to that array or object (rather than being nested deeper into it.)

Take a look at the sequences stuff in the following slides https://www.scottklement.com/presentati ... TA-GEN.pdf -- the part about sequences begins at slide 24.
jonboy49
Posts: 200
Joined: Wed Jul 28, 2021 8:18 pm

Re: Using DATA-GEN + YAJLDTAGEN for iterative build

Post by jonboy49 »

Thanks Scott - I could have sworn that I had tried that but I guess not.

I'll play with it some more and tease out the limits.

Thanks again.
Post Reply