To use a REST API, I must pass a JSON object that looks like this:
{ "series" :
[{
"metric": "custom.powershell.gauge",
"points":[[1434684739, 1000]]
}
]
}
Note the nested array here. I cannot get to reproduce this. Here is my code:
[int][double]$unixtime=get-date ( (get-date).ToUniversalTime() ) -UFormat %s
$obj=@{}
$series=@{}
$array=@()
$points=@()
$value=get-random -Minimum 0 -Maximum 100
$series.add("metric","custom.powershell.gauge")
$points=@(@($unixtime, $value))
$series.add("points",$points)
$obj.Add("series",@($series))
$json=$obj | ConvertTo-Json -Depth 30 -Compress
$json
And here is the output:
{"series":[{"points":[1434685292,95],"metric":"custom.powershell.gauge"}]}
I've tried many things, I cannot get the 2 arrays to be nested, it always end up looking like a single array.
On the same note, came someone explain this please:
> $a=(1,2)
> $a
1
2
> $a | ConvertTo-Json
[
1,
2
]
> $b=($a,$a)
> $b
1
2
1
2
> $b | ConvertTo-Json
[
{
"value": [
1,
2
],
"Count": 2
},
{
"value": [
1,
2
],
"Count": 2
}
]
Where are these value
and Count
coming from?
Thanks for your help.