A node with no name?

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
mmayer4
Posts: 7
Joined: Sun Jul 10, 2022 1:07 pm

A node with no name?

Post by mmayer4 »

I have successfully used HTTPAPI in concert with both data-into and YAJL to read a JSON response. I'm very perplexed as how to read a response that looks like the following.

Code: Select all

[
	{
    		"DealerTitle": "blah blah blah",
    		"DealerID": "blah blah blah",
    		"ContractID": "10526702",
    		"ContractNo": "D0404099",
    		"ServicesUsed": [
    			{
    				ServiceID": "12165005",
    				"ServiceName": "blahblahblah",
    				"Price": "75"
    			},
    			{
    				ServiceID": "121650",
    				"ServiceName": "blahblahblah",
    				"Price": "100"
    			}
    		
    		],
    	}
]
It's an array that has no name. So I don't see how I could use data-into (with a YAJL parser) since a matching data structure needs a name. If I use YAJL there won't be a docNode to do a YAJL_ARRAY_LOOP.

Any suggestions?
Thanks!
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: A node with no name?

Post by jonboy49 »

Off the top of my head this would simply require targeting a DS array with DATA-INTO. I think the RPG will accept any name at the top level but since I’m just doing this on my phone I can’t look it up. Also if that doesn’t work I’m pretty sure YAJLINTO provides a way to name the root ele,ent. It is an option that Scott covers in his presentation.
mmayer4
Posts: 7
Joined: Sun Jul 10, 2022 1:07 pm

Re: A node with no name?

Post by mmayer4 »

Thanks jonboy... I'll keep experimenting with data-into by just giving it a name. I've reviewed several of Scott's presentations on YAJL but I don't recall seeing anything about naming the root. I'll keep looking. If I find a solution, I'll follow up with a post on what worked.
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: A node with no name?

Post by jonboy49 »

In case you are stuck I found time to play and see if my understanding was correct. Here's my version which handles your noname array just fine. RPG fills in the element count in the PSDS with the number of DS array entries, Similalrly I used countprefix to name the count for the inner array. This way allowmissing is not needed.

Here are the relevant code sections:

Code: Select all

Dcl-Ds  PSDS  PSDS;
   elements  int(20)  Pos(372);
End-Ds;

Dcl-Ds  noName  Qualified  Dim(99);
   DealerTitle  char(30);

   DealerID     char(12);
   ContractID  char(12);
   ContractNo   char(10);
   num_ServicesUsed  Int(5);

   Dcl-Ds  ServicesUsed  Dim(99);
      ServiceID  char(10);
      ServiceName  char(30);
      Price  Packed(5:2);
   End-Ds;
End-Ds;

Dcl-s  fileName  varchar(50)
       inz('/Home/Paris/JsonStuff/arrayTest.json');

Data-Into  noName
           %Data(fileName
           : 'case=any doc=file allowextra=yes countprefix=num_')
           %Parser('YAJL/YAJLINTO');
           {/code]
mmayer4
Posts: 7
Joined: Sun Jul 10, 2022 1:07 pm

Re: A node with no name?

Post by mmayer4 »

Oh wow. I never would have thought the PSDS would come into play. This prompted me to actually read the documentation. lol.. Sure enough there she blows. I will test it out and see. Thanks so much!
Post Reply