当我转换Powershell对象时,缺少属性bar
和属性foo
的数组。我使用以下命令将生成的json对象导出到文件:$stackoverflow| ConvertTo-Json | set-content '.\foobar.json'
@stackoverflow = @{
name = "question"
description = "stackoverflow is amazing!"
version = 1.0
myattribute = @(
@{
foo = @("value1")
bar = @("value2")
}
)
}
我希望输出看起来像这样的foo = ["value1"]
和bar = ["value2]
,但是json文件中的实际输出是foo = "value1"
和bar = "value2"
。
谢谢您的帮助。
答案 0 :(得分:0)
通过引用版本号并从myattribute中删除splat,我可以按照您的预期工作:
$stackoverflow = @{
name = "question"
description = "stackoverflow is amazing!"
version = "1.0"
myattribute = (
@{
foo = @("value1")
bar = @("value2")
}
)
}
$stackoverflow | ConvertTo-Json
{
"myattribute": {
"bar": [
"value2"
],
"foo": [
"value1"
]
},
"description": "stackoverflow is amazing!",
"name": "question",
"version": "1.0"
}