-1

I have Json strings in the database I am fetching those with sql query , I need to update this json values with another value how can achieve that .

{
    "ssoredr": [
        "xyz",
        "abc",
        "def",
        "zas"
    ],
    "allowedOther": {
        "FUNDSERV": "dfghj",
        "CINS": "dfghj",
        "ESDID": "fghjk",
        "Compliance Science ID": "3456",
        "OSI IDENTIFIER": "6789"
    },
    "mftConfiguration": {
        "connectionName": "UK-Only",
        "archiveFolder": "/xyz/ua/Archive/"
    }
}

I need to update mftconfigaration with another value

  • Does this answer your question? [Update JSON file using PowerShell](https://stackoverflow.com/questions/37551366/update-json-file-using-powershell) | [Replace values in Json using powershell](https://stackoverflow.com/q/64746363/7571258) – zett42 Dec 14 '20 at 16:31

1 Answers1

0

Using ConvertFrom-Json

$json = @"
{
    "ssoredr": [
        "xyz",
        "abc",
        "def",
        "zas"
    ],
    "allowedOther": {
        "FUNDSERV": "dfghj",
        "CINS": "dfghj",
        "ESDID": "fghjk",
        "Compliance Science ID": "3456",
        "OSI IDENTIFIER": "6789"
    },
    "mftConfiguration": {
        "connectionName": "UK-Only",
        "archiveFolder": "/xyz/ua/Archive/"
    }
}
"@ | ConvertFrom-Json

$json.mftConfiguration.connectionName = "US-Only"
$json | ConvertTo-Json | Out-File c:\text.json # convert back to json string and save to a new file or overwrite the source
Avshalom
  • 8,657
  • 1
  • 25
  • 43