Atom cannot parse JSON created by Powershell


Here’s an example to test out for yourself:

$hash = @{Settings = @(@{First = $false},@{Second = $true});Path = 'C:\Path\String.txt';Text = @{Third = 'Plaintext';Fourth = 'More plain text'}}

$json = ConvertTo-Json -InputObject $hash -Depth 10
$json | Out-File C:\temp\testjson.json

Basically, when I open up the generated JSON file, Atom doesn’t seem to recognize it, though it does still do syntax highlighting. Ctrl+F search doesn’t work at all, on any text in the file, nor does Ctrl+C, it cannot copy any highlighted text to the clipboard. It’s weird. Sublime text doesn’t seem to mind at all, and reads it as a normal JSON file. Why does Atom take issue with it?

Note: If I create the JSON manually in Atom, it works fine. But any JSON generated by the ConvertTo-Json cmdlet in powershell it absolutely hates.


This is probably an encoding problem. Have you tried changing the encoding? I don’t recall what the default encoding is for output from Powershell off the top of my head, but you might try the UTF-16 encodings.


Ah very good, that fixed it right up. I dont’ know a whole lot about encoding, thanks for the help!


Obligatory reference: