0

I have a script that is doing some manipulation on JSON, and then writing them to a file test.json.

$json = @{
    "A"="Hello world";
    "B"= New-Object System.Collections.ArrayList;
}

$json2 = @{
    'C'="Foo Bar";
    'D'=New-Object System.Collections.ArrayList;
}


$json.B += $json2

$json | ConvertTo-Json | Out-File "test.json"

I expected the following json to be created:

{
    "A":  "Hello world",
    "B":  [
              {
                  "D":  [],
                  "C":  "Foo Bar"
              }
          ]
}

however, I found this:

{
    "A":  "Hello world",
    "B":  [
              {
                  "D":  "",
                  "C":  "Foo Bar"
              }
          ]
}

Any clues as to why D doesn't map to an array? Any fixes?

0 Answers0