相关疑难解决方法(0)

Powershell convertfrom-json | 的ConvertTo-CSV

我有一个JSON数据结构如下(这里可能有一些错误,我使用的数据很好):

[{
"id": 12345,
"itemName": "some string",
"sellerId": 123,
"seller": "",
"categoryId": ,
"categoryPath": [
  {
   //more data
  },
  {
   //more data
  }
]}, 
{"id": 12346,
"itemName": "some other string",
"sellerId": 234,
"seller": "",
"categoryId": ,
"categoryPath": [
  {
   //more data
  },
  {
   //more data
  }
]
}]
Run Code Online (Sandbox Code Playgroud)

我想将其转换为csv,以便选定的属性名称成为csv标头,它们的值(仅限深度1)将成为数据.例如

id,itemName,sellerId
12345,"some string",123
12346,"some other string",234
Run Code Online (Sandbox Code Playgroud)

我尝试过使用数百种变体

cat file.json | convertfrom-json | convertto-csv
Run Code Online (Sandbox Code Playgroud)

但没有一个有用.我得到的只是具有对象名称/类型的csv数据,我无法弄清楚如何使它只使用json数据中每个对象的选定属性.

csv powershell json

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

csv ×1

json ×1

powershell ×1