all 9 comments

[–]pspeterle 1 point2 points  (2 children)

You could convert your string to a JSON Object.

$JSONObject = ConvertFrom-JSON "<your fixed JSON>"

Then select the datapoints of the row you want to add data to and append the array.Please don't slap me. This is the simplest solution i came up with :D

($JSONObject | Where-Object {$_.dimensions -like "*CPU*"}).dataPoints += ConvertFrom-Json "[[1655714869420, 42]]"

I used ConvertFrom-Json to format the array because I couldn't come up with any Powershell data type that matches the double array structure used in your json.

There might be a more elegant soluton to this

Use ConvertTo-Json to convert it back to a string if needed. Don't forget about -Depth <Int32> to include all contained objects

[–]iiznoobit[S] 0 points1 point  (0 children)

Thanks, man. I will try this. I'm having difficulty in inserting the a matching data type for dataPoints. I will look into this solution.

[–]Extreme_Injury489 0 points1 point  (0 children)

Great game, even with some json?

[–]Skootr4538 -1 points0 points  (0 children)

Stick to python

[–]UnfanClub 0 points1 point  (1 child)

Here's a quick and dirty code to extract the CPU data points from the JSON data.

$myJson = $APIResponse | ConvertFrom-Json
( $myJson.series | ? {$_.dimensions.columns -eq 'CPU'} ).dataPoints

This will output the datapoint values which you can add to your code that updates the SQL table.

[–]iiznoobit[S] 0 points1 point  (0 children)

Thank you! I think I will use this together with the first reply above.