× 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.



Doesn't yajl_addPreformattedPtr() give you what you need? that appears to be its purpose.


* yajl_addPreformattedPtr(): Insert preformatted data into the JSON
* data stream. (It is up to you to ensure
* that this data is valid JSON data.)
*
* val (input) = key of property to add (or *OMIT if not in an obj)
* val2 (input) = JSON object string in buffer to set as prop value
*
* returns yajl_gen_status_ok upon success,
* or generator status code upon failure.

Looks like you would *Omit the first parameter then supply the pointer to the reformatted string plus its length in the third parm - which doesn't show up in the prototype doc but is present in the actual proto.


Jon

On May 8, 2020, at 6:23 AM, Maria Lucia Stoppa <mlstoppa@xxxxxxxxx> wrote:

Hi all,
Hope you all are doing well.

I am working on an SQLRPGLE program to provide JSON data using SK YAJL
functions.
Everything works as expected except I would like to use another JSON object
as an attribute's value.
I'll explain it better.
This is the DS I populate at the end of my web service program (let's call
it 'main program')
dcl-ds stdOutput qualified inz;
success ind inz(*off);
errCode char(7);
message varchar(128);
data varchar(31000);
end-ds;
'data' is a variable filled with different content depending on the program
called by the main program, and when JSON output is written at the end of
the main program *'data' has already been formatted as a JSON object by the
called program*, which of course has returned it as a string.

Now, when using this code
YAJL_beginObj();
YAJL_addBool('success' : stdOutput.success);
YAJL_addChar('errCode' : stdOutput.errCode);
YAJL_addChar('message' : stdOutput.message);
YAJL_addChar('data' : %trim(stdOutput.data));
YAJL_beginObj('data');
YAJL_endObj();

YAJL_copyBuf(CCSID
: %addr(jsonData)
: %size(jsonData)
: wRetLen);
YAJL_genClose();

to write JSON output, 'stdOutput.data' value is treated as a string,
meaning the JS consumer must parse it into a JSON object to be able to use
it. This is not so bad to do if there are no other choices.

Only, I wonder if there is a way to even add an already set object to the
final JSON. I made some tries with YAJL_copyBufPtr and adding an object
named 'data' omitting the first parameter, all without success.

Am I trying something impossible or missing the elephant in the room?

Thank you

--

Maria Lucia Stoppa
mlstoppa@xxxxxxxxx
--
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.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com


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-2024 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.