Let's start from the beginning of the discussion:
cooldude wrote: ↑Wed Apr 16, 2025 4:48 pm
Trying to read a JSON payload from an IFS file to a string. But ContentLength comes as 0. Any thoughts on what am I missing?
Can you explain what is meant, here? Content-Length has no relationship to reading a file from the IFS. So there is part of the discussion missing, here.. . are you trying to perform an HTTP request using the IFS data? That was not included at all in this message, and is where the problem is likely occurring.
In this message you did this:
cooldude wrote: ↑Wed Apr 16, 2025 4:48 pm
docNode = yajl_stmf_load_tree ( %trim(InpIFSFile) : errMsg );
If ErrMsg <> '';
ErrorMessage = 'json parse: ' + errMsg;
Else;
ContentLength = yajl_stringify( DocNode
: p
: %Size(outBuf));
EndIf;
What this does is read a file from the IFS, parse it into a JSON tree structure, and then convert the JSON tree back to JSON format, I don't know why someone would do that (it uses a lot of computing power to arrive back where you started.) But it has nothing whatsoever to do with a content-length. Indeed, there is no explanation of where you are even seeing a content-length.
In the next message:
cooldude wrote: ↑Wed Apr 16, 2025 6:45 pm
Also tried the below, which did not work either:
Dcl-S outString char(65535) Inz;
docNode = yajl_stmf_load_tree ( %trim(InpIFSFile) : errMsg );
node = YAJL_object_find(docNode: 'purchaseOrder');
outString = YAJL_get_string(node);
What is meant by "did not work"? This code reads a file, then finds the 'purchaseOrder' property in the document node. Then it tries to interpret it as a string (but it is not, it is an array of objects). What are you expecting to happen here? Are you trying to stringify just the purchaseOrder part of the document without the enclosing object?
What does this have to do with the Content-Length you mentioned at the start of the thread? Or is it a completely a completely separate issue?
Next message:
cooldude wrote: ↑Wed Apr 16, 2025 7:13 pm
Another related question:
The objective here is to send a payload (JSON/XML) from an IFS path (file is in .txt format) to an external API using http_url_post - for which trying to get the full payload into a string.
But can we directly send the IFS file to external API, using http_url_post or a different one? Please advise, if I can refer any example.
This is the first mention you've made of httpapi, you've mentioned http_url_post. But that is an old, obsolete routine. If you want the old obsolete routine to send a file from the ifs, it's http_url_post_stmf. But I would use the newer routines, http_req() (or possibly http_stmf() depending on what you want to do with the result that comes back.)
But what does this have to do with the preceding posts? They were using YAJL to interpret the JSON. This post is talking about sending a file over the internet. Two completely different things. Though, at least this message makes sense with regards to the content-length.
Next message:
cooldude wrote: ↑Thu Apr 17, 2025 2:12 pm
FYI - I was able to use QSYS2.IFS_READ table function to read data from IFS file.
This, again, leaves me very confused. This reads IFS data into a variable. It doesn't intepret the json (as per your first two posts) or send it over a network (as per your third.) If this "solved" the problem, then obviously you're doing other things with it after you read it from disk, but you don't tell us what that is.