Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Converting Json to CSV

$
0
0

I am using powershell to get some data from a webservice which is returning json.

I wish to write this out to a CSV file, but not sure how to do it.

So far:

$webRequest = [System.Net.WebRequest]::Create( $loc )
				$webRequest.Headers.Add($auth2)
				$return = $webRequest.GetResponse()
#				$usagein = Invoke-WebRequest -Uri $loc -Headers @{"authentication"=$authent} -timeoutsec 6000 | ConvertFrom-Json 
                $stream = $return.getResponseStream()
				$sr = new-object IO.StreamReader($stream)
				$result = $sr.ReadToEnd()
				$return.close()
				$resultjson = $result | ConvertFrom-Json
				$result > ".\output_normal.txt"
				$resultjson > ".\output_json.txt"
				write-host "done for" $beginrange $endrange

I end up with two files, one with the raw output and one with nicly formatted Json. 

How can I write to a CSV file?

Thanks.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>