“在PowerShell中构造json字符串时,”正在更改为\

时间:2017-06-25 08:44:14

标签: json powershell

我正在创建一个JSON格式的字符串。输出是正确的,除了所有qoutes已被\ char替换而不是“

{
    \$schema\: \https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#\,
    \contentVersion\: \1.0.0.0\,
    \parameters\: {
\type\:  \web\,
\name\:  \Cluster\,
\hockeyAppToken\:  \\,
\hockeyAppId\:  \\,
\regionId\:  \southcentralus\,
\requestSource\:  \IbizaAIExtension\
}
}

生成Json的代码

$fullDoc = '
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": ' + $armsettings + '}'

$json = $fullDoc |  ConvertTo-Json -depth 100
$json = $json.Replace("\r","")
$json = $json.Replace("\n",([Environment]::NewLine))
$json = $json.Replace("@{","{")
$json = $json.Trim()
$json = $json.Replace($json.Substring(0,1),"")         

Write-Host $json

有关如何解决此问题的任何想法?

这是正确的格式化文档

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "type": {
        "value": "web"
    },
    "name": {
        "value": "Cluster"
    },
    "hockeyAppToken": {
        "value": ""
    },
    "hockeyAppId": {
        "value": ""
    },
    "regionId": {
        "value": "southcentralus"
    },
    "requestSource": {
        "value": "IbizaAIExtension"
    }
}
}

1 个答案:

答案 0 :(得分:0)

$fullDoc | ConvertTo-Json | ConvertFrom-Json