0

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:

Json conversion to CSV

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?

2
  • $File = "$PSScriptRoot\Getconnector.json" $FileName1 = "$PSScriptRoot\output.csv" Commented Mar 4, 2017 at 16:20
  • With the powershell pipeline, often the best solution with something like this to "half split the problem" and break the pipe. It's been years since I worked with PS, but a quick Google found Show-Object as an option. Commented Mar 4, 2017 at 18:37

2 Answers 2

1

Just use rows property to export data

$content = Get-Content -Raw $file | ConvertFrom-Json
$content.rows | export-csv 'somepath' -NoTypeInformation
Sign up to request clarification or add additional context in comments.

Comments

0

try this

get-content "C:\temp\test.txt" | ConvertFrom-Json | % {$_.Rows} | export-csv "C:\temp\test2.txt" -NoType

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.