powershell - 如何使用 Powershell 将 json 输出转换为数组/列表(到 json 输出)
问题描述
想要使用 Powershell 将 json 输出转换为数组或列表。
我尝试使用 转换输出ConvertFrom-Json
,然后获取键名称和值。需要建议。
json输出:
{
"demo1": {
"type": [
"tuple",
[
[
"list",
"string"
],
[
"list",
"string"
]
]
],
"value": [
[
"123"
],
[
"456"
]
]
},
"demo2": {
"type": [
"tuple",
[
"string",
"string"
]
],
"value": [
"abc",
"xyz"
]
}
}
使用 Powershell 想要将其转换如下:
demo1 = [["123"],["456"]]
demo2 = ["abc","xyz"]
提前致谢。
解决方案
似乎是对 convertfrom-json 的一个非常简单的使用:
$a = get-content file.json | convertfrom-json
$a.demo1.value
123
456
$a.demo2.value
abc
xyz
你想要它作为json?
$a.demo1.value | ConvertTo-Json -Compress
[["123"],["456"]]
$a.demo2.value | ConvertTo-Json -Compress
["abc","xyz"]
推荐阅读
- calculated-field - Amazon Quicksight 计算字段 - maxIf 或 maxOver?
- php - auth()->attempt($request->only('email','password')) - 不工作
- scheme - 高阶函数和 Set 如何在 Scheme 上工作?
- c - 声明与 PieVectTable 不兼容
- javascript - 如何在没有 jQuery 或 ID 的情况下在 HTML 字符串中查找某些元素
- r - 如何纠正估计边际均值 (EMM) 的标准误差?
- python - Pygame 如何知道第 1 层(背景)与屏幕上显示的精灵是什么?
- sql - 用户活动 - SQL 查询
- java - 未读取字符串,以便修改数组中的元素。我应该使用什么方法?
- python - 将 Python 嵌套字典转换为表或列表列表(没有 Pandas)