如何使用Jolt将二维数组转换为目标键值对对象?
二维数组转键值对对象的Jolt配置方案
需求说明
输入为包含表头数组和数据数组的二维结构,需将表头元素作为键、对应位置的数据元素作为值,生成目标键值对对象。
正确Jolt配置
[ { "operation": "shift", "spec": { "1": { "*": { "@": "@(2,0[&1])" } } } } ]
配置逻辑解释
"1":定位到输入数组的第二个元素(数据数组,数组索引从0开始)"*":遍历数据数组中的每一个元素"@":指代当前遍历到的数据元素值"@(2,0[&1])":向上回溯2层到根数组,取第一个元素(表头数组)中索引与当前数据元素索引&1匹配的元素,作为键名
验证效果
输入
[ [ "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" }
内容的提问来源于stack exchange,提问作者Drew Nicolette
相关产品推荐
相关产品推荐

