如何使用JOLT将列格式JSON数组转换为行格式数组
JOLT转换方案:列结构JSON转行结构数组
输入JSON
{ "data": { "fullentrydateGroup": [ { "fullentrydateList": { "fullentrydate": [ { "fullentrydate": "20240906", "position": "1" } ] }, "index": "1" }, { "fullentrydateList": { "fullentrydate": [ { "fullentrydate": "20240907", "position": "1" } ] }, "index": "2" } ], "creditamtGroup": [ { "creditamtList": { "creditamt": [ { "position": "1", "creditamt": "C" } ] }, "index": "2" } ] } }
目标输出JSON
{ "statementEntries": [ { "fullentrydate": "20240906", "creditamt": "" }, { "fullentrydate": "20240907", "creditamt": "C" } ] }
JOLT转换规范
[ { "operation": "shift", "spec": { "data": { "fullentrydateGroup": { "*": { "fullentrydateList": { "fullentrydate": { "*": { "fullentrydate": "statementEntries[&4].fullentrydate" } } } } }, "creditamtGroup": { "*": { "creditamtList": { "creditamt": { "*": { "creditamt": "statementEntries[&4].creditamt" } } } } } } } }, { "operation": "default", "spec": { "statementEntries": { "*": { "creditamt": "" } } } } ]
转换逻辑说明
- Shift操作:
- 遍历
fullentrydateGroup的每一项,通过[&4]回溯层级获取当前项的数组索引(对应index数值),将fullentrydate值映射到statementEntries数组对应位置的对象中。 - 用同样逻辑处理
creditamtGroup,把creditamt值按索引匹配到对应行。
- 遍历
- Default操作:
- 遍历
statementEntries的所有行,为缺失creditamt字段的行补充空字符串,保证每行字段完整性。
- 遍历
内容的提问来源于stack exchange,提问作者Malaiselvan
相关产品推荐
相关产品推荐

