powershellconvertfrom-json

Retrieve value from Json object with field having dots and hyphen in powershell


I want to retrieve value of a field present in json object. The filed name has dots and hyphen.

For eg:

$json = @"
{
"Stuffs": 
    {
            "Name.new-name": "Darts",
            "Type": "Fun Stuff"
    }
}
"@

How can I get the value Darts?

I tried some approaches like

$x = $json | ConvertFrom-Json
$x.Stuffs.(Name.new-name) 

But it doesn't work.


Solution

  • Try this

    $x.Stuffs.'Name.new-name'