|
Nothing blows up or returns errors but this code only returns a single '{' in the buffer so I'm probably doing several things wrong. I'm very unsure about yajl_genfromNode.
Dcl-s Root Like(yajl_val);
Dcl-s errMsg VarChar(500) Inz(' ');
Dcl-s ptrJSONContent Pointer;
Dcl-s rtnLen Int(10);
Dcl-s lenJSONContent Int(10);
Dcl-s wrkContent SQLTYPE(Clob:128000);
EXEC SQL
SELECT a.Transaction_Content
INTO :wrkContent
FROM cvWebTx A
WHERE a.AppID = :wrkRecID;
rc = yajl_genOpen(*On);
ptrJSONContent = %Addr(wrkContent_Data);
lenJSONContent = wrkContent_Len;
Root =
yajl_buf_load_tree(ptrJSONContent:lenJSONContent:errMsg);
rc = yajl_beginObj();
rc = yajl_genFromNode(' ':Root);
rc = yajl_endObj();
rc = yajl_saveBuf('/tmp/prettyJSON.json':errMsg);
yajl_genClose();
I appreciate other suggestions about other open source. Since YAJL is already installed and being used I'd like to stick with it.
If your requirements are different and its important to do this in program code... this is unusual, but should be possible with YAJL. Open an existing JSON document into a tree using yajl_stmf_load_tree() (or one of the other yajl tools that loads a tree) and then use YAJL's generator to create output. There's a routine called YAJL_genFromNode that you can call, pass a node (such as the document node returned by
yajl_stmf_load_tree) and it will add that entire tree to the generated JSON. If you've configured the JSON generate to generate in "pretty"
format, the yajl_genFromNode will essentially copy the structure, but the output will be "pretty".
Good Luck
On 10/27/2020 3:09 PM, Jack Prucha wrote:
I want to present a JSON payload to the user in an easy-to-read format. Output like JSONFormatter.org. Linking to a web site is a non-starter so I'm searching for something iSeries based.
I have Scott's YAJL software installed and am using it with Data-Into. However, I don't see an example in his thorough documentation to take any JSON and pretty up the formatting for human viewing. There's a CLE pgm in his YAJLLIB72 called JSON_Refmt but I can't figure it out.
Most RPGLE JSON open source I see is designed to create or disassemble JSON - not display it.
Any suggestions?
TIA
Jack
As an Amazon Associate we earn from qualifying purchases.
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.