请求Jolt无限深度树字段转换:重命名子节点name与title字段
Jolt 转换实现无限层级 children 字段重命名
转换规范(Jolt Spec)
[ { "operation": "shift", "spec": { "person": "person", "personTitle": "personTitle", "children": { "*": { "name": "&1.childname", "title": "&1.childtitle", "children": { "*": { "@(1,name)": "&2.childname", "@(1,title)": "&2.childtitle", "@(1,children)": "&2.children" } } } } } }, { "operation": "remove", "spec": { "children": { "*": { "children": { "*": { "children": { "": "" } } } } } } } ]
规范说明
- 无限层级支持:通过Jolt的路径相对引用(
&1、&2)实现递归遍历,不管children嵌套多少层,都会自动处理每个节点的字段转换。 - 字段重命名:对所有
children数组内的节点,将name重命名为childname,title重命名为childtitle,根节点的person和personTitle保持原样。 - 空数组清理:第二个
remove操作会移除嵌套层级中空的children数组,和示例输出格式一致,不需要此效果可直接删除该操作。
输入示例
{ "person": "Adam", "personTitle": "MR", "children": [ { "name": "John", "title": "MR", "children": [ { "name": "Sarah", "title": "MR", "children": [] } ] }, { "name": "Jimmy", "title": "MR", "children": [ { "name": "Stephen", "title": "MR", "children": [] } ] } ] }
输出示例
{ "person": "Adam", "personTitle": "MR", "children": [ { "childname": "John", "childtitle": "MR", "children": [ { "childname": "Sarah", "childtitle": "MR", "children": [] } ] }, { "childname": "Jimmy", "childtitle": "MR", "children": [ { "childname": "Stephen", "childtitle": "MR" } ] } ] }
内容的提问来源于stack exchange,提问作者Dharanidhar
相关产品推荐
相关产品推荐

