简体   繁体   中英

" is being changed to \ when constructing json string in PowerShell

I am creating a JSON formatted string. The output is correct except that all qoutes has been replaced with the \\ char instead of "

{
    \$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\
}
}

The code that generates the 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

Any idea on how to fix this?

This is the correct formatted document

{
"$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"
    }
}
}
$fullDoc | ConvertTo-Json | ConvertFrom-Json 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM