0

I want to create a HTTP REST request with Powershell. This request contains a JSON Object with an empty array. Unfortunately Powershell creates an empty string instead of an empty array with "[]":

$body_firewall_creation = @{
    name = "FW01"
    rules = @(
        @{
            description = "SSH"
            direction = "in"
            port = "22"
            protocol = "tcp"
            source_ips = @() # <--- This is the empty array
        }
    )
}

Output:

{
    "name":  "FW01",
    "rules":  [
                  {
                      "port":  "22",
                      "protocol":  "tcp",
                      "description":  "SSH",
                      "direction":  "in",
                      "source_ips":  ""
                  }
              ]
}

It also does not work if I put some values inside the array. The output will be "value1 value2 value3".

ssd_rider
  • 45
  • 8

0 Answers0