arraysjsonpowershellmember-enumeration

How to enter press square brackets in PowerShell on JSON File


How can I query change value of the "type" string in my JSON file with PowerShell? I can't get to the "type" string.

JSON file

{
"name":  "b",
"compatibilityLevel":  1400,
"model":  {
              "culture":  "c",
              "dataSources":[
                                  {
                                      "type":  "structured"
                                  }
                            ]
         }}

PowerShell

$pathToJson =  "C:\Model.bim"

$a = Get-Content $pathToJson | ConvertFrom-Json

$a.'model.dataSources.type' = "c"

$a | ConvertTo-Json -Depth 10  | Set-Content $pathToJson

Solution

  • tl;dr

    $a.model.dataSources[0].type = 'c'
    

    Note the need to specify index [0], because $a.model.dataSources is an array.


    AS for what you tried:

    $a.'model.dataSources.type' = "c"