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



as promised...

https://github.com/jeffersonvaughn/ibmi-json-beautify

Call jsonpretty passing in a streamfile path/filename, which contains a
json string
The file is updated to a pretty json format...

example...

before:
{"env":"xxx","command":"getListOfAPIs","payload":[{"apiLibrary":"COREIRST"},{"apiLibrary":"COREIADM"}]}


after:
{
"command": "getListOfAPIs",
"env": "xxx",
"payload": [
{
"apiLibrary": "COREIRST"
},
{
"apiLibrary": "COREIADM"
}
]
}

Jay

On Tue, Feb 1, 2022 at 8:37 AM Jack Prucha <Jack.Prucha@xxxxxxx> wrote:

Thanks specifically to Scott some years ago and Jon for many other JSON
answers I wrote a pgm to display prettified JSON in a subfile. The JSON is
read from a CLOB in a DB2 file. The commented out yaj_savBuff might be
useful for your uses, I don't know.

These are the important bits:

Dcl-s BeginPos Int(5:0);
Dcl-s DelimPos Int(5:0);

// YAJL variables
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 rc Int(10);
Dcl-s prettyJSON Char(65535);

//
=======================================================================
Begsr FmtPrettyJSON;
//
-----------------------------------------------------------------------

rc = yajl_genOpen(*On);

ptrJSONContent = %Addr(wrkContent_Data);
lenJSONContent = wrkContent_Len;
Root = yajl_buf_load_tree(ptrJSONContent:lenJSONContent:errMsg);

rc = yajl_genFromNode(*Omit:Root);

yajl_tree_free(Root);

//rc = yajl_saveBuf('/tmp/prettyJSON.json':errMsg);
rc = yajl_copyBuf(0:%Addr(prettyJSON):65535:rtnLen);

yajl_genClose();

EndSr;

//
=======================================================================
Begsr SflLoadAll;
//
-----------------------------------------------------------------------

Clear RR0101;
BeginPos = 1;

Dow 1 = 1;

DelimPos = %Scan(x'25':prettyJSON:BeginPos);

// Not found - end of JSON
If DelimPos = 0;
// Find end of last "record" in JSON - no delimiter
// Done - Get out of loop
Leave;
EndIf;

SflLoadOne(prettyJSON:BeginPos:DelimPos);

// Setup next scan
BeginPos = DelimPos + 1;

EndDo;

// Display records & "End"
If RR0101 > *Zero;
SflDsp = *On;
SflEnd = *On;
// Point back to 1st page
RR0101 = 1;

// No records
Else;
// Display "No Records"
EndIf;

EndSr;

//
=====================================================================
Dcl-Proc SflLoadOne;
// ---------------------------------------------------------------------
// Extract single JSON element & add to subfile
// ---------------------------------------------------------------------
Dcl-pi *N;
JSONText Like(prettyJSON);
BegPOS Like(BeginPos);
EndPOS Like(DelimPos);
End-Pi;

Dcl-s wrkBegPos Like(BeginPos);
Dcl-s wrkEndPos Like(DelimPos);
Dcl-s wrkStrLen Like(DelimPos);
Dcl-s ExtJSONText Like(s1JSON);

// ---------------------------------------------------------------------

wrkBegPos = BegPos;
wrkEndPos = EndPos;
wrkStrLen = wrkEndPos - wrkBegPos;

RR0101 = RR0101 + 1;
Clear s1JSON;
s1JSON = %Subst(JSONText:wrkBegPos:wrkStrLen) ;
Write PN01SF01;

Return;

END-Proc;

This email, including any documents, files, or previous email messages
attached to it, has been sent from an email account of College Foundation
Inc., (CFI) and may contain confidential, proprietary, or legally
privileged information belonging to CFI. If you are not the intended
recipient, any dissemination, distribution, or copying of this email or its
attachments is strictly prohibited. If you have received this email in
error, please immediately notify the sender by email and destroy the
original email and any attachments.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-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 ...

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.