Problem copying a node to a stream file

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
imaxeman69
Posts: 23
Joined: Thu Mar 17, 2022 2:29 pm

Problem copying a node to a stream file

Post by imaxeman69 »

I'm using this code to copy the top node to a stream file:

Code: Select all

           if docNode <> *null;
             inboundFile = '/P44/Inbound/P44ShipmentUpdate_' +
                           %char(%date():*iso0) + '_' +
                           %char(%time():*hms0) + '.json';
             yajl_save_string_stmf(docNode:
                                   inboundFile:
                                   errMsg);
             if errMsg <> *blanks;
               EXEC SQL
                 INSERT INTO Wserlgfl
                 VALUES(CURRENT TIMESTAMP,
                        'Copy Error',
                        errMsg);
             endif;  
I'm not getting a stream file. errMsg is blank.
I know it's not null, because this code is working:

Code: Select all

             nodeq = YAJL_object_find(docNode: 'shipment');
             if nodeQ <> *null;
It's falling through the rest of the code.
imaxeman69
Posts: 23
Joined: Thu Mar 17, 2022 2:29 pm

Re: Problem copying a node to a stream file

Post by imaxeman69 »

Sorry, this is where docNode comes from:

Code: Select all

           docNode = yajl_stdin_load_tree(UTF8encoded : errMsg);

imaxeman69
Posts: 23
Joined: Thu Mar 17, 2022 2:29 pm

Re: Problem copying a node to a stream file

Post by imaxeman69 »

Ok, I see that I can only write out string nodes. My SQL was wrong, which is why I wasn't getting anything in my error log.

So, Is there a way to capture the entire JSON string into a variable or a stream file?
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: Problem copying a node to a stream file

Post by Scott Klement »

YAJL_stringify() will let you output everything at a given node to a variable.
imaxeman69
Posts: 23
Joined: Thu Mar 17, 2022 2:29 pm

Re: Problem copying a node to a stream file

Post by imaxeman69 »

Thanks, Scott.
imaxeman69
Posts: 23
Joined: Thu Mar 17, 2022 2:29 pm

Re: Problem copying a node to a stream file

Post by imaxeman69 »

Getting this error: ERROR decoding EStdString

I pass the pointer to the doc node to another program. Then do the work to save the document node to the stream file and get this error.
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: Problem copying a node to a stream file

Post by Scott Klement »

I am not familiar with the message "ERROR decoding EStdString" -- I haven't seen that before. I searched the source code for YAJL, and nothing reports that error.

I did a Google, and the only matches I find are with the IBM i debugger -- perhaps this is coming from the debugger?
imaxeman69
Posts: 23
Joined: Thu Mar 17, 2022 2:29 pm

Re: Problem copying a node to a stream file

Post by imaxeman69 »

Same here. And, I was in debug when I saw that. I was looking at the second argument of the YAJL_STRINGIFY procedure.

Thanks,
Post Reply