英文:
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/上的演示是
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论