"Invalid array passed" when parsing JSON "Invalid array passed" when parsing JSON json json

"Invalid array passed" when parsing JSON


Try to pipe to Out-String before piping to ConvertFrom-Json:

Get-Content $file | Select -Skip 1 | Out-String | ConvertFrom-Json

In your working example the JSON code is a string while the non-working example returns a collection of lines. Piping to Out-String converts the collection to a single string, which is what the InputObject parameter accept.


Alternatively you can use Get-Content -Raw which will retrieve the JSON as a single string.

See this post for more info: http://blogs.technet.com/b/heyscriptingguy/archive/2014/04/23/json-is-the-new-xml.aspx


The var myMap = isn't json, it's javascript. Delete the first line and it will be fine.

EDIT:

Oh, you are skipping the first line. It may be that there's a carriage return missing in the last line of the file, and Powershell 3 is more sensitive to it. It works fine in Powershell 5.1 even without a carriage return at the end.