Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过powershell更新sendgrid个性化json文件_Json_Powershell_Sendgrid - Fatal编程技术网

通过powershell更新sendgrid个性化json文件

通过powershell更新sendgrid个性化json文件,json,powershell,sendgrid,Json,Powershell,Sendgrid,要通过powershell更新下面的sendgrid personalizations json文件,以添加一个或多个电子邮件id 发件人:- { "personalizations": [{ "to": [{"email": "abc1@xyz.com"}, {"email": "abc2@xyz.com"}] }] } 致:- 已尝试将其保

要通过powershell更新下面的sendgrid personalizations json文件,以添加一个或多个电子邮件id

发件人:-

{
    "personalizations": [{
        "to": [{"email": "abc1@xyz.com"}, {"email": "abc2@xyz.com"}]
    }]
}
致:-

已尝试将其保存到文件并使用“添加成员”,但没有成功

$EmailTemplateFilePath = "C:\EmailTemplate.json"
$body = [System.IO.File]::ReadAllText($EmailTemplateFilePath)
$body = ConvertFrom-Json -InputObject $body
请注意,不幸需要
-Depth 3
,以确保从JSON解析的对象正确转换回JSON-请参阅

上述收益率:

{
“个性化”:[
{
“致”:[
“@{电子邮件=abc1@xyz.com}",
“@{电子邮件=abc2@xyz.com}",
“@{电子邮件=abc3@xyz.com}"
]
}
]
}

很高兴听到这个消息,@KushalSolanki;我的荣幸。
$EmailTemplateFilePath = "C:\EmailTemplate.json"
$body = [System.IO.File]::ReadAllText($EmailTemplateFilePath)
$body = ConvertFrom-Json -InputObject $body
# Parse the input JSON into a custom object ([pscustomobject]).
$obj = (@'
{
  "personalizations": [{
      "to": [{"email": "abc1@xyz.com"}, {"email": "abc2@xyz.com"}]
  }]
}
'@ | ConvertFrom-Json)

# Append a new custom object with a new email address.
$obj.personalizations[0].to += [pscustomobject] @{ email = 'abc3@xyz.com' }

# Convert back to JSON.
$obj | ConvertTo-Json -Depth 3