David Ebbo
David Ebbo

Reputation: 43193

Converting the json output of a console app to a PowerShell object

Suppose I have a foo.exe console app that returns some json, and I want to turn that into a PowerShell object.

I was hoping to simply write:

$o = foo.exe | ConvertFrom-Json

But this doesn't work because the output of the console app is treated as an Array instead of a string. I can instead write:

$o = ([string]foo.exe) | ConvertFrom-Json

which feels dirtier than I was hoping.

Question: can I do better than what I have above to get a PowerShell object out of the output of a console app?

Upvotes: 2

Views: 627

Answers (1)

serhiyb
serhiyb

Reputation: 4833

As an option:

$o = foo.exe | Out-String | ConvertFrom-Json

Upvotes: 1

Related Questions