如何将JSON多值输出转换为正确的JSON格式?

萨西什·库玛

我正在尝试将下面的输出转换为有效的json输出。无法使用Shell脚本解决此问题。
电流输出:

{ “adapter Type” : “Pass” , “Result” : “ 
    ABCD/AAZZ
    ABCD/AHAG” }, 
 { “Adapter Slot” : “Pass” , “Result” : “
    PCI Slot 3
    PCI Slot 2” }, 
 { “WWN” : “Pass” , “Result” : “ 
    10:01:02:90
    10:02:03:90” }

预期输出(json):

{
    "CUT Sheet ": [{
        "Host Adapter Type": "ABCD/AAZZ",
        "Adapter Physical Location/Slot": "PCI Slot 3",
        "HBA WWN": "10:01:02:90"
    }, {
        "Host Adapter Type": "ABCD/AHAG",
        "Adapter Physical Location/Slot": "PCI Slot 2",
        "HBA WWN": "10:02:03:90"
    }]
}

可以转换吗?有人可以提供解决方案。

法比奥·阿尔梅达(FábioAlmeida)

我错过了当前输出中的括号以及结果之间的换行(可能是剪切和粘贴问题),但是输出:

[   {
    "adapterType": "Pass",
    "Result": "ABCD/AAZZ\nABCD/AHAG"   },   {
    "AdapterSlot": "Pass",
    "Result": "PCI Slot 3\nPCI Slot 2"   },   {
    "WWN": "Pass",
    "Result": "10:01:02:90\n10:02:03:90"   } ]

重定向到:

| jq'map_values(.Result | split(“ \ n”))| 转置| map({“主机适配器类型”:。[0],“适配器物理位置/插槽”:。[1],“ HBA WWN”:。[2]})'| jq -n'。“剪切表” | = [输入]'

生成输出:

{
  "CUT Sheet ": [
    [
      {
        "Host Adapter Type": "ABCD/AAZZ",
        "Adapter Physical Location/Slot": "PCI Slot 3",
        "HBA WWN": "10:01:02:90"
      },
      {
        "Host Adapter Type": "ABCD/AHAG",
        "Adapter Physical Location/Slot": "PCI Slot 2",
        "HBA WWN": "10:02:03:90"
      }
    ]
  ]
}

你需要安装jq

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章