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

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -