Jolt – 将数组转化为键值对

huangapple go评论90阅读模式
英文:

Jolt - Array into Key Value Pairs

问题

以下是您要翻译的内容:

我正在尝试使用 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"
  ]
]
英文:

I am trying to convert this input below to the expected output using Jolt

Here's my Input:

[
  [
    "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"
  ]
]

I am trying to convert it into this output -

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

I tried using this Jolt -

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

But it came back like this -

[
  [
    "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"
  ]
]

答案1

得分: 1

你可以使用以下转换规范,比如

[
  { // 将各个数组的每个组件分散到其各自的对象中
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&.comp&1"
      }
    }
  },
  { // 匹配每个对象内的组件
    "operation": "shift",
    "spec": {
      "*": {
        "@comp1": "@comp0"
      }
    }
  }
]

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

Jolt – 将数组转化为键值对

英文:

You can use the following shift transformation specs such as

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

the demo on the site http://jolt-demo.appspot.com/ is

Jolt – 将数组转化为键值对

huangapple
  • 本文由 发表于 2023年5月30日 01:05:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76359147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定