I am having trouble converting json data to csv.
I have the following json data tha is pulled from a web api and loaded into $EnergyData:
{ "energyDetails": { "timeUnit": "WEEK", "unit": "Wh", "meters": [ { "type": "Production", "values": [ { "date": "2015-11-02 00:00:00" }, { "date": "2015-11-09 00:00:00" }, { "date": "2015-11-16 00:00:00", "value": 2953 } ] } ] } }
If I run this code I only get the date column in the csv
$EnergyData = (Invoke-WebRequest "$EnergyUrl").Content | ConvertFrom-Json $Data = $EnergyData.energyDetails.meters.values | ConvertTo-Csv -Delimiter "," -NoTypeInformation If($Data -ne $null) { [io.file]::WriteAllLines("$PSScriptRoot\$FileName",$Data) }
How do I get value 2953 into the csv, the other date entries need to be in there too but with a null or “” value.