首页 > 解决方案 > JQ 横向列表作为地图

问题描述

我想将下面的 JSON 转换为 Map。但它以列表的形式出现。

{
  "_embedded": {
    "items": [
      {
         "order": 1,
        "technical": {
          "id": 1,
          "_links": {
            "self": {
              "href": "/profile/api/v3/service/40/technical"
            }
          }
        }
      },
       {
        "order": 2,
        "technical": {
          "id": 1,
          "_links": {
            "self": {
              "href": "/profile/api/v3/service/40/technical"
            }
          }
        }
      }
    ]
  }
}

预期格式:

{
  "1": "/profile/api/v3/service/40/technical",
  "2": "/profile/api/v3/service/40/technical"
}

但我得到:::

[
  {
    "1": "/profile/api/v3/service/40/technical"
  },
  {
    "2": "/profile/api/v3/service/40/technical"
  }
]

JQ查询:::

._embedded.items | map({(.order| tostring ) : .technical._links.self.href} )

请帮助,在此先感谢..

代码片段 - https://jqplay.org/s/cEzh5_LimP

标签: jsonjq

解决方案


只需| add添加到 jq 程序的末尾即可。


推荐阅读