Discussion:
Iterate Json
(too old to reply)
Mysta
2014-08-06 19:03:15 UTC
Permalink
So using the new SAM 8 appliances I noticed there is a health.json function.

Is there any way to iterate through this to build a sort of report?

Right now if I iterate it only returns the first item.
goonitsupport
2014-08-07 15:28:53 UTC
Permalink
Post by Mysta
So using the new SAM 8 appliances I noticed there is a health.json function.
Is there any way to iterate through this to build a sort of report?
Right now if I iterate it only returns the first item.
Better to perform a call/reply and retrieve the json output as http.body. You can then parse and process the resulting JSON string.

Here is an example (leave a comment if this is of use to you) http://www.goonit.co.uk/notes/?p=237

Best regards
Mysta
2014-08-07 20:20:20 UTC
Permalink
Post by goonitsupport
Post by Mysta
So using the new SAM 8 appliances I noticed there is a health.json function.
Is there any way to iterate through this to build a sort of report?
Right now if I iterate it only returns the first item.
Better to perform a call/reply and retrieve the json output as http.body. You can then parse and process the resulting JSON string.
Here is an example (leave a comment if this is of use to you) http://www.goonit.co.uk/notes/?p=237
Best regards
That would definitely work, but why not use the json parser? so you can output to spreadsheet and such.
Eddie Hartman
2014-08-11 14:29:52 UTC
Permalink
Post by Mysta
Post by goonitsupport
Post by Mysta
So using the new SAM 8 appliances I noticed there is a health.json function.
Is there any way to iterate through this to build a sort of report?
Right now if I iterate it only returns the first item.
Better to perform a call/reply and retrieve the json output as http.body. You can then parse and process the resulting JSON string.
Here is an example (leave a comment if this is of use to you) http://www.goonit.co.uk/notes/?p=237
Best regards
That would definitely work, but why not use the json parser? so you can output to spreadsheet and such.
Absolutely, Mysta. If you are using TDI 7.1.1 or SDI 7.2 you can use something like:

json = work.getString("http.bodyAsString");
jsObj = fromJson(json);
jsEntry = work.fromJSON(json);

The second line gives you a javascript object, which is easy to traverse and explore, while the last line gives you a hierarchical TDI entry. This can also be traversed pretty easily, as well as using DOM calls like getElementsByTagName() and search(xpathExpr).

And of course, you can this sort of stuff interactively in the Debugger, exploring the return payload to your hearts desire. Note that even though the Debugger cannot print out a js object, you can always convert it to a json string with toJson(jsObj).

Hope this help!
-Eddie
m***@gmail.com
2019-09-04 09:46:57 UTC
Permalink
Has anyone able to iterate through all the child nodes for webseal json using fromJSON? Below is the sample response from ISAM LMI. I'm trying to retrieve the IP and port of the junction, status and label but not able to retrieve IP and port.

'{"identifier":"name","label":"name","items":[{"children":[{"children":[{"name":"rp1/jct1192.168.10.130:8080","health":"0","label":"192.168.10.130:8080"}],"name":"rp1/jct1","health":"0","label":"/jct1"},{"children":[{"name":"rp1/mga192.168.10.1:443","health":"0","label":"192.168.10.1:443"}],"name":"rp1/mga","health":"0","label":"/mga"},{"children":[{"name":"rp1/isam192.168.10.1:443","health":"0","label":"192.168.10.1:443"}],"name":"rp1/isam","health":"0","label":"/isam"},{"name":"rp1/","health":"0","label":"/"}],"name":"rp1","health":"0","label":"rp1"}]}'

Thanks,
Post by Eddie Hartman
Post by Mysta
Post by goonitsupport
Post by Mysta
So using the new SAM 8 appliances I noticed there is a health.json function.
Is there any way to iterate through this to build a sort of report?
Right now if I iterate it only returns the first item.
Better to perform a call/reply and retrieve the json output as http.body. You can then parse and process the resulting JSON string.
Here is an example (leave a comment if this is of use to you) http://www.goonit.co.uk/notes/?p=237
Best regards
That would definitely work, but why not use the json parser? so you can output to spreadsheet and such.
json = work.getString("http.bodyAsString");
jsObj = fromJson(json);
jsEntry = work.fromJSON(json);
The second line gives you a javascript object, which is easy to traverse and explore, while the last line gives you a hierarchical TDI entry. This can also be traversed pretty easily, as well as using DOM calls like getElementsByTagName() and search(xpathExpr).
And of course, you can this sort of stuff interactively in the Debugger, exploring the return payload to your hearts desire. Note that even though the Debugger cannot print out a js object, you can always convert it to a json string with toJson(jsObj).
Hope this help!
-Eddie
Eddie Hartman
2019-09-04 17:48:46 UTC
Permalink
Post by m***@gmail.com
Has anyone able to iterate through all the child nodes for webseal json using fromJSON? Below is the sample response from ISAM LMI. I'm trying to retrieve the IP and port of the junction, status and label but not able to retrieve IP and port.
'{"identifier":"name","label":"name","items":[{"children":[{"children":[{"name":"rp1/jct1192.168.10.130:8080","health":"0","label":"192.168.10.130:8080"}],"name":"rp1/jct1","health":"0","label":"/jct1"},{"children":[{"name":"rp1/mga192.168.10.1:443","health":"0","label":"192.168.10.1:443"}],"name":"rp1/mga","health":"0","label":"/mga"},{"children":[{"name":"rp1/isam192.168.10.1:443","health":"0","label":"192.168.10.1:443"}],"name":"rp1/isam","health":"0","label":"/isam"},{"name":"rp1/","health":"0","label":"/"}],"name":"rp1","health":"0","label":"rp1"}]}'
Thanks,
Post by Eddie Hartman
Post by Mysta
Post by goonitsupport
Post by Mysta
So using the new SAM 8 appliances I noticed there is a health.json function.
Is there any way to iterate through this to build a sort of report?
Right now if I iterate it only returns the first item.
Better to perform a call/reply and retrieve the json output as http.body. You can then parse and process the resulting JSON string.
Here is an example (leave a comment if this is of use to you) http://www.goonit.co.uk/notes/?p=237
Best regards
That would definitely work, but why not use the json parser? so you can output to spreadsheet and such.
json = work.getString("http.bodyAsString");
jsObj = fromJson(json);
jsEntry = work.fromJSON(json);
The second line gives you a javascript object, which is easy to traverse and explore, while the last line gives you a hierarchical TDI entry. This can also be traversed pretty easily, as well as using DOM calls like getElementsByTagName() and search(xpathExpr).
And of course, you can this sort of stuff interactively in the Debugger, exploring the return payload to your hearts desire. Note that even though the Debugger cannot print out a js object, you can always convert it to a json string with toJson(jsObj).
Hope this help!
-Eddie
Would that be the 'label' property, Matha? Here is some script that you can use to play around with walking the hierarchy tree of your json object. Just create a new AL, add an Empty Script and paste this in. Then if you start the Debugger you can step into the code and check the data at any time:
----
json = '{"identifier":"name","label":"name","items":[{"children":[{"children":[{"name":"rp1/jct1192.168.10.130:8080","health":"0","label":"192.168.10.130:8080"}],"name":"rp1/jct1","health":"0","label":"/jct1"},{"children":[{"name":"rp1/mga192.168.10.1:443","health":"0","label":"192.168.10.1:443"}],"name":"rp1/mga","health":"0","label":"/mga"},{"children":[{"name":"rp1/isam192.168.10.1:443","health":"0","label":"192.168.10.1:443"}],"name":"rp1/isam","health":"0","label":"/isam"},{"name":"rp1/","health":"0","label":"/"}],"name":"rp1","health":"0","label":"rp1"}]}';

job = fromJson(json);
items = job.items;
for (i in items) {
children = items[i].children;
if (children) {
for (j in children) {
grandChildren = children[j].children;
if (grandChildren) {
for (k in grandChildren) {
item = grandChildren[k];
task.logmsg("--> " + item.label);
}
}
}
}
}
----

Hope this helps

Loading...