0

I have a json file with below contents

{
    "createOrReplace": {
        "object": {
            "database": "DB_NAME"
        },
        "database": {
            "name": "DB_NAME",
            "compatibilityLevel": 1400,
            "model": {
                "culture": "en-IN",
                "dataSources": [{
                    "name": "somename",
                    "connectionString": "somevalue",
                    "impersonationMode": "impersonateServiceAccount",
                    "annotations": [{
                        "name": "ConnectionEditUISource",
                        "value": "SqlServer"
                    }]
                }]
            }
        }
    }
}

and I am using following a PowerShell script to update the name under dataSources.

$JsonFilePath = "path-to-json-file"
$JsonData = Get-Content $JsonFilePath -raw | ConvertFrom-Json
$JsonData.createOrReplace.database.model.dataSources[0].name = "ssasservername"
$JsonData | ConvertTo-Json | set-content $JsonFilePath

Can anyone help me to set a value of an object inside the array?

1 Answers1

0
$JsonData.createOrReplace.database.model.dataSources[0].name = "ssasservername"

Also note: Unexpected ConvertTo-Json results? Answer: it has a default -Depth of 2:

$JsonData | ConvertTo-Json -Depth 9 | set-content $JsonFilePath
iRon
  • 20,463
  • 10
  • 53
  • 79