ConvertTo-JSON an array with a single item

前端 未结 4 1010
失恋的感觉
失恋的感觉 2020-12-03 16:58

I\'m trying to create a JSON-serialized array. When that array contains only one item I get a string, not an array of strings (in JSON).

Multiple Items (works as exp

4条回答
  •  隐瞒了意图╮
    2020-12-03 17:12

    Faced the same issue today. Just to add, if you have an object like this

    @{ op="replace"; path="clientName"; value="foo"}
    

    then you have to specify it as

    ConvertTo-Json @( @{ op="replace"; path="clientName"; value="foo"} )
    

    The double @s can become confusing sometimes.

提交回复
热议问题