I have a JSON data structured as following (there may be some mistakes here, the data I\'m using is fine):
[{
\"id\": 12345,
\"itemName\": \"some string\",
\
In short you need to do something like this:
(Get-Content file.json -Raw | ConvertFrom-Json) | Select id,itemName,sellerId | Convertto-CSV -NoTypeInformation
The first problem was that Get-Content
was passing individual lines to ConvertFrom-Json
which is not what it wants. Using the -Raw
switch passes it in its entirety.
The (Get-Content file.json -Raw | ConvertFrom-Json)
needs to be in parentheses as that allows us to continue with the pipe. The properties are not accessible without doing this. It looks like it is trying to pass the entire object instead of its individual parts down the pipe.
-NoTypeInformation
removes lines like this
#TYPE Selected.System.Management.Automation.PSCustomObject