Hashtables from ConvertFrom-json have different type from powershells built-in hashtables, how do I make them the same?

前端 未结 5 1299
天命终不由人
天命终不由人 2020-12-09 10:33

I have a json file (test.json) that looks something like this:

{
    \"root\":
    {
        \"key\":\"value\"
    }
}

I\'m loading it into

5条回答
  •  我在风中等你
    2020-12-09 10:46

    The example was for a relatively shallow source object (not nested objects in the properties).

    Here's a version that will go 2 levels deep into the source object, and should work with your data:

    $data = @{}
    
    foreach ($propL1 in $x.psobject.properties.name)
       {
         $data[$propL1] = @{}
         foreach ($propL2 in $x.$propL1.psobject.properties.name)
            {
              $data[$PropL1][$PropL2] = $x.$propL1.$propL2
            }
        }
    
    
    $data.root.keys
    
    key
    

提交回复
热议问题