Reputation: 33
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:
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?
Upvotes: 0
Views: 2466
Reputation: 17462
try this
get-content "C:\temp\test.txt" | ConvertFrom-Json | % {$_.Rows} | export-csv "C:\temp\test2.txt" -NoType
Upvotes: 0
Reputation: 72171
Just use rows property to export data
$content = Get-Content -Raw $file | ConvertFrom-Json
$content.rows | export-csv 'somepath' -NoTypeInformation
Upvotes: 1