I’ve got an API that returns the following:
JavaScript
x
13
13
1
{
2
"data": {
3
"columns": [
4
"epoch_timestamp_millieseconds",
5
"cpu_used_percent"
6
],
7
"values": [
8
[
9
1615230210000,
10
28.24
11
],
12
13
I’m able to get the second metric using the following three lines of code:
JavaScript
1
4
1
<#assign metricvalue = jsonObj.data.values[0]>
2
<#assign arr = metricvalue[1]>
3
&value=${arr}
4
&value would equal 28.24.
Is there a way to combine these into one line of code?
I’m looking for something like this:
&value=jsonObj.data.values[0].[1]
The issue is the [1]
doesn’t have a label
Advertisement
Answer
Your code is almost correct. Just a small correction. Remove the .
between [0]
and [1]
. You don’t need to use .
to specify the index. You only need to use it to specify the property/key
.
The code should be like
JavaScript
1
3
1
jsonObj.data.values[0][0] // 1615230210000
2
jsonObj.data.values[0][1] // 28.24
3