Sep 14
Firefox, PowerShell and Encoding

So, developing a website, in which I use PowerShell to go over some SharePoint Lists and generate a JSON file.

Happy days for Edge, Chrome, IE and Safari using this method, not so much with Firefox.

Firefox just produces a popup:

image

Taking a look in the Firefox console, the problem is the response text of the JSON file is not encoded with ASCII, Edge, Chrome, IE and Safari can deal with this fine.

Firefox is complaining that while the request went thru OK (HTTP STATUS: 200), the JSON is invalid / malformed.

image

The solution, Add –Encoding ASCII to the Out-File line of PowerShell and this encodes the newly created JSON file with ASCII encoding and not UTF-8.

My PowerShell:

$Cred = Get-Credential

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", 'application/json; odata=verbose')
$partners_url = "http://public.archongnosis.com.au/_api/web/lists/getbytitle('Partners')/items"
$result_partners = Invoke-RestMethod -Uri $partners_url -Method Get -Headers $headers -Credential $Cred
$result_partners | Out-File C:\inetpub\Sites\new.archongnosis.com.au\json\partners.json –Encoding ASCII

Hope this helps!

Comments

There are no comments for this post.