简体   繁体   中英

Convert JSON dict in Bash to Powershell

I need some help passing this json dict to the variable RESPONSE . But I am unsure how to convert this to powershell from bash. I tried using piping to | ConvertTo-Json -Compress | ConvertTo-Json -Compress but couldn't quite get it right

RESPONSE="$(cat <<EOT
{
  "spec": {
    "instance": "$NODENAME",
    "hostname": true,
    "container": [
      {
        "seccontent": {
          "objectA": true
        },
        "image": "$IMAGENAME",
        "command": [ "tester", "--target", "1", "--mount", "--test", "--test", "--net", "--pid", "--", "bash", "-l" ]
      }
    ]
  }
}
EOT
)"

Try multiple lines string like this:

> $RESPONSE=@'
{
  "spec": {
    "instance": "$NODENAME",
    "hostname": true,
    "container": [
      {
        "seccontent": {
          "objectA": true
        },
        "image": "$IMAGENAME",
        "command": [ "nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--net", "--pid", "--", "bash", "-l" ]
      }
    ]
  }
}
'@

And, then convert to JSON:

> $RESPONSE | ConvertTo-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