ConvertTo-Json截断简单的json列表

时间:2019-03-12 15:48:35

标签: json powershell convertto-json

我有以下PowerShell代码:

IForm(42); //or 
IForm($ID);

我得到的输出是这样:

$rawJson = '{
  "A": [
         {
           "Attr1": "Value1",
           "Attr2": 0
         }
       ],
  "B": [
         {
           "SimpleList": [ 
                           "Entry1",
                           "Entry2"
                         ],
           "Id": "myId"
         }
       ]
}';

$jsonConverted = $rawJson | ConvertFrom-Json;
$jsonConverted.A[0].Attr2 = 1;
Write-Host ($jsonConverted | ConvertTo-Json);

我期望的输出是这样:

{
    "A":  [
              {
                  "Attr1":  "Value1",
                  "Attr2":  1
              }
          ],
    "B":  [
              {
                  "SimpleList":  "Entry1 Entry2",
                  "Id":  "myId"
              }
          ]
}

“ SimpleList”被截断为单个字符串而不是保留单个项目,这是我做错了吗?

0 个答案:

没有答案