Issue using yajl_saveBuf

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/
tbrantley
Posts: 9
Joined: Fri Jul 14, 2023 9:25 pm

Re: Issue using yajl_saveBuf

Post by tbrantley »

Sweet! I've been able to get this to work using yajl_copyBufStr()!!

I would like to be able to use the yajl_copyBuf function.

When I change my code to use the yajl_copyBuf function. I receive the error below.

Any ideas on what may be causing this?

dcl-s JSONDataLength int(10);
dcl-c ToCCSID const(37);
dcl-s jsonData SQLTYPE(CLOB:2000000) inz;


%len(jsonData) = %len(jsonData:*max);
yajl_copyBuf( ToCCSID: %addr(jsonData: *Data): %len(jsonData): JSONDataLength);
%len(jsonData) = JSONDataLength;


Errors Messages

*RNF0229 20 1 *DATA is only valid for %ADDR when the definition is a
varying-length item; *DATA is ignored.
*RNF0235 20 1 *MAX is only valid for %LEN when the definition is a
varying-length item; *MAX is ignored.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Issue using yajl_saveBuf

Post by Scott Klement »

Like the message says, you can only use *DATA and *MAX when working with a VARYING/VARCHAR variable.
tbrantley
Posts: 9
Joined: Fri Jul 14, 2023 9:25 pm

Re: Issue using yajl_saveBuf

Post by tbrantley »

Thanks Scott! That worked!

Would you recommend doing anything different before I put clob data from buffer into the HTTP POST?

Program compiles correctly but I'm getting an SQL state of 01004 once it tries to POST data.

dcl-s JSONDataLength int(10);
dcl-c ToCCSID const(37);
dcl-s jsonData SQLTYPE(CLOB:1000000) inz;
dcl-s myUrl varchar(500);
dcl-s myhdr varchar(2000);

yajl_copyBuf( ToCCSID: %addr(jsonData):
%len(jsonData): JSONDataLength);
jsonData_Len = %len(%trimr(jsonData_data));

EXEC SQL
SELECT RESPONSE_MESSAGE, RESPONSE_HTTP_HEADER
INTO :rspData, :rspHdr
FROM TABLE(QSYS2.HTTP_POST_VERBOSE(
CAST(trim(:myUrl) AS VARCHAR(500)),
CAST(trim(:jsonData) AS CLOB(2G)),
CAST(trim(:myHdr) AS VARCHAR(2000))));


I appreciate all of your help!

Trent
tbrantley
Posts: 9
Joined: Fri Jul 14, 2023 9:25 pm

Re: Issue using yajl_saveBuf

Post by tbrantley »

This is strange...

It's cutting off the first 4 characters from the front of the json when it copies data from buffer.

It should start like this.

{
"payorId": "company[09]",
jsonErr.PNG
jsonErr.PNG (20.36 KiB) Viewed 7997 times
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Issue using yajl_saveBuf

Post by Scott Klement »

....because you're telling it the address of your data structure, instead of the address of the data subfield in your data structure...

%addr(jsonData_Data)

Please see the earlier message in this same thread where I explained to you how CLOB works.
tbrantley
Posts: 9
Joined: Fri Jul 14, 2023 9:25 pm

Re: Issue using yajl_saveBuf

Post by tbrantley »

Thanks for all the help, Scott! I appreciate it!
Post Reply