如何使用Jolt将扁平JSON转换为对应索引的JSON对象数组?
使用Jolt将扁平JSON转换为带唯一索引的JSON对象数组
需求:将扁平JSON对象转换为JSON对象数组,数组中的每个元素对应原对象中的一个唯一索引编号,输出数组的元素数量需与原对象中的索引数量一致。
示例1
输入JSON 1
{ "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters.location": "test", "batters.batter[0].id": "1001", "batters.batter[0].type": "Regular", "batters.batter[1].id": "1002", "batters.batter[1].type": "Chocolate" }
输出JSON 1
[ { "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters.location": "test", "batters.batter.id": "1001", "batters.batter.type": "Regular" }, { "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters.location": "test", "batters.batter.id": "1002", "batters.batter.type": "Chocolate" } ]
示例2
输入JSON 2
{ "[0].id": "0001", "[0].type": "donut", "[0].name": "Cake", "[0].ppu": 0.55, "[0].batters.location": "test", "[0].batters.batter[0].id": "1001", "[0].batters.batter[0].type": "Regular", "[0].batters.batter[1].id": "1002", "[0].batters.batter[1].type": "Chocolate", "[1].id": "0002", "[1].type": "donut", "[1].name": "Cake2", "[1].ppu": 0.75, "[1].batters.location": "test2", "[1].batters.batter[0].id": "1002", "[1].batters.batter[0].type": "Regular", "[1].batters.batter[1].id": "1003", "[1].batters.batter[1].type": "Chocolate" }
输出JSON 2
[ { "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters.location": "test", "batters.batter.id": "1001", "batters.batter.type": "Regular" }, { "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters.location": "test", "batters.batter.id": "1002", "batters.batter.type": "Chocolate" }, { "id": "0002", "type": "donut", "name": "Cake2", "ppu": 0.75, "batters.location": "test2", "batters.batter.id": "1002", "batters.batter.type": "Regular" }, { "id": "0002", "type": "donut", "name": "Cake2", "ppu": 0.75, "batters.location": "test2", "batters.batter.id": "1003", "batters.batter.type": "Chocolate" } ]
内容的提问来源于stack exchange,提问作者Sumit Manna
相关产品推荐
相关产品推荐

