回答編集履歴

2

2023/03/30 09:46

投稿

melian
melian

スコア19840

test CHANGED
@@ -1,21 +1,8 @@
1
1
  カラム数を決め打ちにしていますが、以下の様な感じでしょうか。
2
2
  ```powershell
3
3
  $cols = (1..4) | %{ "col" + $_ }
4
- $json = Import-CSV "C:\test.txt" -Header $cols | ConvertTo-Json
4
+ $json = Import-CSV "C:\test.txt" -Header $cols | ConvertTo-Json -Compress
5
5
  $json
6
6
 
7
- # [
8
- # {
9
- # "col1": "11111",
10
- # "col2": "22222",
11
- # "col3": "33333",
12
- # "col4": "44444"
13
- # },
14
- # {
15
- # "col1": "aaaaaa",
7
+ # [{"col1":"11111","col2":"22222","col3":"33333","col4":"44444"},{"col1":"aaaaaa","col2":"bbbbb","col3":"ccccc","col4":"dddddd"}]
16
- # "col2": "bbbbb",
17
- # "col3": "ccccc",
18
- # "col4": "dddddd"
19
- # }
20
- # ]
21
8
  ```

1

2023/03/30 09:14

投稿

melian
melian

スコア19840

test CHANGED
@@ -1,8 +1,8 @@
1
1
  カラム数を決め打ちにしていますが、以下の様な感じでしょうか。
2
2
  ```powershell
3
- $cols = (1..4) | % {"col" + $_ }
3
+ $cols = (1..4) | %{ "col" + $_ }
4
- $arr = Import-CSV "C:\test.txt" -Header $cols | ConvertTo-Json
4
+ $json = Import-CSV "C:\test.txt" -Header $cols | ConvertTo-Json
5
- $arr
5
+ $json
6
6
 
7
7
  # [
8
8
  # {