powershell - How to create CSV output from JSON? -


my json query returns weather data parse using powershell. want delete unnecessary items , export final file csv or txt.

$json = get-content -raw $path | convertfrom-json #get json object directory , convert powershell object $hourly = $json.hourly_forecast $fcttime = $hourly.fcttime $pretty = $fcttime | select pretty  $temp = $hourly.temp $eng = $temp | select english  $parsed = $eng, $pretty 

it seems work okay when output $parsed in csv has object properties rather values of $eng , $pretty. there easier way parse json files or way can combine arrays in last step?

expand properties. also, export-csv exports properties of objects, not values of array. should work:

get-content -raw $path |   convertfrom-json |   select -expand hourly_forecast |   select @{n='pretty';e={$_.fcttime | select -expand pretty}},          @{n='english';e={$_.temp | select -expand english}} |   export-csv 'c:\output.csv' -notype 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -