Convert string to object

I have a query that returns a string that looks like this.
{“name”:“MyName”,“id”:“492e54abee”}

I am trying to find a way to convert it to an object, so I can pull the name and id.

I cleaned up the string so it looks like this. Not sure if that is needed.
name:MyName,id:492e54abee

I’m pretty sure I’ve seen a simple way to do this, but I can’ think of how.

Your format is a JSON string. You can use ConvertFrom-Json:

$obj = '{"name":"MyName","id":"492e54abee"}' | ConvertFrom-Json
$obj.name
$obj.id

[quote quote=286705]Your format is a JSON string. You can use ConvertFrom-Json:

PowerShell
<textarea class="urvanov-syntax-highlighter-plain print-no" style="-moz-tab-size: 4; font-size: 14px !important; line-height: 18px !important; z-index: 0; opacity: 0;" readonly="readonly" data-settings="dblclick">$obj = '{"name":"MyName","id":"492e54abee"}' | ConvertFrom-Json $obj.name $obj.id</textarea>
1
2
3
$obj = '{"name":"MyName","id":"492e54abee"}' | ConvertFrom-Json
$obj.name
$obj.id
[/quote] Awesome! Thanks. I knew there was an easy way to do it.