[英]export csv from json file using powershell
我確實有一個json文件,例如:{“ skip”:0,“ take”:100,“ rows”:[{“ WG”:“ 1013”,“ Werkgever”:“ 1013”,“ Cao”:“ 0000 “}]}
現在我確實需要使用powerhsell將其轉換為csv文件
"WG","Werkgever","Cao"
"1013","1013","0000"
腳本是:
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
只有我會錯過這個價值。
"WG","Werkgever","Cao"
"","",""
我做錯了什么?
只需使用行屬性即可導出數據
$content = Get-Content -Raw $file | ConvertFrom-Json
$content.rows | export-csv 'somepath' -NoTypeInformation
嘗試這個
get-content "C:\temp\test.txt" | ConvertFrom-Json | % {$_.Rows} | export-csv "C:\temp\test2.txt" -NoType
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.