I have converted the following JSON file to powershell representation object.

{
"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\"
    }
]

}

After doing some computations with powershell representation I would like to save it to file as JSON. But command $jsonRepresentation | ConvertTo-Json | Out-File "D:\dummy_path\file.json" saves it in this way

{
    "computer":  [
                     {
                         "children":  " ",
                         "full_path_on_file_sys":  "T:\Dropbox\"
                     }
                 ]
}

Question: how to achieve correct saving of complex powershell JSON representation?

推荐答案

-depth argument for ConvertTo-Json solves the issue.

$jsonRepresentation | ConvertTo-Json -depth 100 | Out-File "D:\dummy_path\file.json"

Json相关问答推荐

如何在Swift中使用JSON编码器的泛型

规范化JSON数据

使用 JOLT 将日期格式转换为 JSON

Jolt 变换以展平 json 字符串数组

如何使用SQLite Trigger将JSON对象数组转换为新记录?

将环境变量值从 yaml 传递到 json

如何在 Flutter 中遍历嵌套的动态 JSON 文件

将 JSON 文件放在哪里以在 Angular 8 应用程序中加载静态 JSON 数据?

如何迭代、动态加载我的表单输入元素,然后在 React 中的表单提交上检索输入值?

阅读 JSON 正文 Firebase 云函数

Powershell - 如何从 JSON 中删除/过滤元素但保留其余部分?

使用 Ansible 解析来自 Juniper 交换机的 JSON 输出

Powershell JSON 操作

如何判断字符串是否为json格式

Spring MVC 4:application/json内容类型设置不正确

Python - 如何将 JSON 文件转换为数据框

在 Rails 中使用 JSON 创建嵌套对象

在 JSON.NET 中序列化派生类时的字段顺序

通过 JSON 发送 64 位值的公认方式是什么?

使用 JSON.NET 序列化/反序列化对象字典