0

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.

Clijsters
  • 4,031
  • 1
  • 27
  • 37
PREETI BANSAL
  • 185
  • 2
  • 12

1 Answers1

1

Try this

$x.Stuffs.'Name.new-name'
Mike
  • 38
  • 5
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/24574891) – Clijsters Nov 14 '19 at 08:15
  • ...it literally does..replace the last line in the original question with what I wrote above, and you'll get the value "Darts" outputted. – Mike Nov 17 '19 at 22:44
  • No, it doesn't. Please read the links I provided on how to write good answers. A code Snippet without any exnplanation is not a sufficient answer. – Clijsters Nov 18 '19 at 12:53