json Jolt -数组到键值对

jrcvhitl  于 2023-05-30  发布在  其他
关注(0)|答案(1)|浏览(132)

我尝试使用Jolt将下面的输入转换为预期的输出
下面是我的输入:

[
  [
    "station_name",
    "station_longname"
  ],
  [
    "10 Mile Brook Dam Water Level Daily Value, South W",
    "10 Mile Brook Dam Water Level Daily Value, South West Region"
  ]
]

我试着把它转换成这个输出-

{
  "station_name": "10 Mile Brook Dam Water Level Daily Value, South W",
  "station_longname": "10 Mile Brook Dam Water Level Daily Value, South West Region"
}

我试着用这个Jolt -

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "@": "[&1]"
        }
      }
    }
  }
]

但结果是这样的-

[
  [
    "station_name",
    "10 Mile Brook Dam Water Level Daily Value, South W"
  ],
  [
    "station_longname",
    "10 Mile Brook Dam Water Level Daily Value, South West Region"
  ]
]
hc2pp10m

hc2pp10m1#

您可以使用以下shift转换规范,例如

[
  { // dissipate each component of the respective arrays
    // to their respective object
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&.comp&1"
      }
    }
  },
  { // match components within each object
    "operation": "shift",
    "spec": {
      "*": {
        "@comp1": "@comp0"
      }
    }
  }
]

网站http://jolt-demo.appspot.com/上的***演示***是

相关问题