编写Dynamic Jolt规格处理外层数组第2元素含嵌套数组场景
Jolt规格修正:适配含嵌套identifiers数组的routeSegments
输入JSON
{ "routeSegments": [ { "id": "seg1", "name": "Segment 1" }, { "id": "seg2", "name": "Segment 2", "identifiers": [ { "type": "CODE", "value": "ABC123" }, { "type": "ID", "value": "X789" } ] } ] }
预期输出JSON
{ "routes": [ { "segmentId": "seg1", "segmentName": "Segment 1" }, { "segmentId": "seg2", "segmentName": "Segment 2", "codes": [ { "codeType": "CODE", "codeValue": "ABC123" }, { "codeType": "ID", "codeValue": "X789" } ] } ] }
原尝试的Jolt规格
[ { "operation": "shift", "spec": { "routeSegments": { "*": { "id": "routes[&1].segmentId", "name": "routes[&1].segmentName" } } } } ]
修正后的Jolt规格
[ { "operation": "shift", "spec": { "routeSegments": { "*": { "id": "routes[&1].segmentId", "name": "routes[&1].segmentName", "identifiers": { "*": { "type": "routes[&3].codes[&1].codeType", "value": "routes[&3].codes[&1].codeValue" } } } } } } ]
修正说明
- 用
&3对应外层routeSegments的数组下标,确保每个identifiers里的元素能精准映射到所属的routes条目下的codes数组 - 保留原有的基础字段映射逻辑,补上嵌套数组的处理规则,解决部分元素包含
identifiers嵌套数组时的转换异常问题
内容的提问来源于stack exchange,提问作者Thiyagaraj Narayanan
相关产品推荐
相关产品推荐

