- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 12:26 PM
Hi,
How can I extract this "text":"nzur12345uap.XYZPROD.MSAD.XYZ.NET"?
Evaluator: com.glide.script.RhinoEcmaError: Cannot read property "0" from undefined
script : Line(33) column(0)
==> 33: gs.print(respJObj.data.result_sets[0].rows[0].data[2]);
{
"data":{
"now":"2022/02/15 16:50:48 GMT-0000",
"max_available_age":"",
"result_sets":[
{
"age":0,
"id":296900,
"rows":[
{
"id":1059534335,
"cid":3331268787,
"data":[
[
{
"text":"nzur12345uap.XYZPROD.MSAD.XYZ.NET"
}
],
[
{
"text":"Windows Server 2016 Standard"
}
],
[
{
"text":"1"
}
]
]
}
]
}
]
}
}
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 01:18 PM
Hi, heres an example:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 01:50 PM
Hi,
I tried in a background script in my PDI:
Script:
{
"data":{
"now":"2022/02/15 16:50:48 GMT-0000",
"max_available_age":"",
"result_sets":[
{
"age":0,
"id":296900,
"rows":[
{
"id":1059534335,
"cid":3331268787,
"data":[
[
{
"text":"nzur12345uap.XYZPROD.MSAD.XYZ.NET"
}
],
[
{
"text":"Windows Server 2016 Standard"
}
],
[
{
"text":"1"
}
]
]
}
]
}
]
}
}
I assigned the output to the var "json"
and accessed it in the gs log.
Output:
*** Script: nzur12345uap.XYZPROD.MSAD.XYZ.NET
If you want to find out how to access specific lines in JSON take a look at jsonparser. Once you select a node, it will show the path to access it (highlighted yellow)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 03:46 PM
Tested with the following script.
var jsonStr = '{"data":{"now":"2022/02/15 16:50:48 GMT-0000","max_available_age":"","result_sets":[{"age":0,"id":296900,"rows":[{"id":1059534335,"cid":3331268787,"data":[[{"text":"nzur12345uap.XYZPROD.MSAD.XYZ.NET"}],[{"text":"Windows Server 2016 Standard"}],[{"text":"1"}]]}]}]}}';
var jsonObj = JSON.parse(jsonStr);
gs.log(jsonObj.data.result_sets[0].rows[0].data[0][0].text);
Execution result:
*** Script: nzur12345uap.XYZPROD.MSAD.XYZ.NET
Detailed Explanation in line:
{
"data":{ <-- (1) get "data" object -- "jsonObj.data"
"now":"2022/02/15 16:50:48 GMT-0000",
"max_available_age":"",
"result_sets":[ <-- (2) get "result_sets" object. -- "jsonObj.data.result_sets" -->
<-- (3) "[" implies it's an array. Add "[0]" to get the first element of this array -- "jsonObj.data.result_sets[0] -->
{
"age":0,
"id":296900,
"rows":[ <-- (4) get "rows" object -- "jsonObj.data.result_sets[0].rows -->
<-- (5) "[" implies it's an array. Add "[0]" to get the first element of this array -- "jsonObj.data.result_sets[0].rows[0] -->
{
"id":1059534335,
"cid":3331268787,
"data":[ <-- (6) get "data" object -- "jsonObj.data.result_sets[0].rows[0].data -->
<-- (7) "[" implies it's an array. Add "[0]" to get the first element of this array -- "jsonObj.data.result_sets[0].rows[0].data[0] -->
[ <-- (8) "[" implies it's an array. Add "[0]" to get the first element of this array -- "jsonObj.data.result_sets[0].rows[0].data[0][0] -->
{
"text":"nzur12345uap.XYZPROD.MSAD.XYZ.NET" <-- get "text" object -- jsonObj.data.result_sets[0].rows[0].data[0][0].text -->
}
],
[
{
"text":"Windows Server 2016 Standard"
}
],
[
{
"text":"1"
}
]
]
}
]
}
]
}
}