我已将以下 JSON 文件转换为 powershell 表示对象。
{
"computer": [
{
"children": [
{
"children": [ {
"children": [ {
"path": "T:\Dropbox\kvaki.html",
"name": "kvaki",
"type": "url",
"url": "http://example.com"
} ],
"path": "T:\Dropbox\",
"name": "Njusha",
"type": "folder"
}, {
"path": "T:\Dropbox\Europa.html",
"name": "Europa",
"type": "url",
"url": "http://example.com"
}, {
"path": "T:\Dropbox\math.html",
"name": "math",
"type": "url",
"url": "http://example.com"
} ],
"path": "T:\Dropbox\",
"name": "Money",
"type": "folder"
}
],
"full_path_on_file_sys": "T:\Dropbox\"
}
]
}
在使用 powershell 表示进行一些计算后,我想将其保存为 JSON 文件。
但是命令 $jsonRepresentation |转换为 JSON | Out-File "D:\dummy_path\file.json"
就是这样保存的
{
"computer": [
{
"children": " ",
"full_path_on_file_sys": "T:\Dropbox\"
}
]
}
问题:如何实现复杂的powershell JSON表示的正确保存?
最佳答案
ConvertTo-Json 的
-depth 参数解决了这个问题。
$jsonRepresentation | ConvertTo-Json -depth 100 | Out-File "D:\dummy_path\file.json"
https://stackoverflow.com/questions/22275724/
相关文章:
json - 如何在 Django JSONField 数据上聚合(最小/最大等)?
javascript - 如何检查 JSON 响应元素是否为数组?
javascript - jQuery:在继续之前可以等待 $.get 完成加载吗?
java - 使用 Jackson 将 Json 反序列化为其他类层次结构
ruby-on-rails - 如何将 JBuilder View 的 JSON 表示形式呈现为字符
ios - JSONSerialization 选项有什么作用,它们如何改变 jsonResult?