LoginSignup
1
3

More than 5 years have passed since last update.

Powershellでcsvをjsonにパースする

Last updated at Posted at 2018-10-06

簡単で感動


PS /Users/tetsuya/yamazon/sandbox> # 読み込み(cat)
PS /Users/tetsuya/yamazon/sandbox> gc ./a.csv
"no","name","attr"
"1","yamazon1","aws engineer"
"2","yamazon2","aws engineer"
"3","yamazon3","aws engineer"
"4","yamazon4","aws engineer"

PS /Users/tetsuya/yamazon/sandbox> # csv -> psobject 変換
PS /Users/tetsuya/yamazon/sandbox> gc ./a.csv |ConvertFrom-Csv

no name     attr
-- ----     ----
1  yamazon1 aws engineer
2  yamazon2 aws engineer
3  yamazon3 aws engineer
4  yamazon4 aws engineer

PS /Users/tetsuya/yamazon/sandbox> # csv -> psobject -> Json 変換
PS /Users/tetsuya/yamazon/sandbox> gc ./a.csv |ConvertFrom-Csv |ConvertTo-Json
[
  {
    "no": "1",
    "name": "yamazon1",
    "attr": "aws engineer"
  },
  {
    "no": "2",
    "name": "yamazon2",
    "attr": "aws engineer"
  },
  {
    "no": "3",
    "name": "yamazon3",
    "attr": "aws engineer"
  },
  {
    "no": "4",
    "name": "yamazon4",
    "attr": "aws engineer"
  }
]
PS /Users/tetsuya/yamazon/sandbox> 
PS /Users/tetsuya/yamazon/sandbox> わーい
わーい : The term 'わーい' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ わーい
+ ~~~
+ CategoryInfo          : ObjectNotFound: (わーい:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

PS /Users/tetsuya/yamazon/sandbox> # わーい の実行エラー
PS /Users/tetsuya/yamazon/sandbox> 
PS /Users/tetsuya/yamazon/sandbox> pwsh -v # バージョン確認(若干古い)
PowerShell v6.1.0-preview.1

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3