Export csv from the json file using powershell

advertisements

I do have a json file like this: { "skip" : 0, "take" : 100, "rows" : [ { "WG": "1013", "Werkgever": "1013", "Cao": "0000" } ]}

Now I do need to convert this to csv file like this using powerhsell

"WG","Werkgever","Cao"
"1013","1013","0000"

The script is:

Json conversion to CSV

Get-Content -Raw $file |
  ConvertFrom-Json |
  select @{n='WG';e={$_.WG | select -Expand WG}},
         @{n='Werkgever';e={$_.Werkgever | select -Expand Werkgever}},
         @{n='Cao';e={$_.Cao| select -Expand Cao}}|
Export-Csv $FileName1 -NoType

Only I do miss the value.... It comes out like:

"WG","Werkgever","Cao"
"","",""

What do I do wrong?


try this

get-content "C:\temp\test.txt" | ConvertFrom-Json | % {$_.Rows} | export-csv "C:\temp\test2.txt" -NoType