gpt4 book ai didi

apache-nifi - NiFi 中的 JoltTransformJSON 处理器(没有任何父标签的 json)

转载 作者:行者123 更新时间:2023-12-04 03:21:24 24 4
gpt4 key购买 nike

我需要使用 Nifi 中的 JoltTransformJSON 转换 JSON 数据,这是我用于转换的规范:

[{
"operation": "shift",
"spec": {
"*": {
"Header": {
"readOn": "created_date_time",
"fileName": "readFile"
},
"Data": {
"id": "Id",
"first_name": "First_Name",
"last_name": "Last_Name",
}
}
}}]

我的输入数据:

[{
"Header": {
"readOn": "2017/04/18 10:55:05",
"fileName": "sample1.csv",
"recordNum": 1
},
"Data": {
"last_name": "Martin",
"id": 21,
"first_name": "Clarence"
}
}, {
"Header": {
"readOn": "2017/04/18 10:55:05",
"fileName": "sample.csv",
"recordNum": 2
},
"Data": {
"last_name": "Graham",
"id": 22,
"first_name": "Walter"
}
}]

输出我得到的:

{
"created_date_time": ["2017/04/18 10:55:05", "2017/04/18 10:55:05"],
"readFile": ["sample1.csv", "sample2.csv"],
"Id": [21, 22],
"First_Name": ["Clarence", "Walter"],
"Last_Name": ["Martin", "Graham"]
}

所需的输出:

[{
"recordNum": 1,
"Header": {
"created_date_time": "2017/04/18 10:55:05",
"readFile": "getusroi.csv"
},
"Data": {
"Last_Name": "Martin",
"Id": 21,
"First_Name": "Clarence"
}
}, {
"recordNum": 2,
"Header": {
"created_date_time": "2017/04/18 10:55:05",
"readFile": "getusroi.csv"
},
"Data": {
"Last_Name": "Graham",
"Id": 22,
"First_Name": "Walter"
}
}]

问题:有人可以指导我在哪些地方需要更改我的颠簸规范以获得所需的转换输出。

最佳答案

诀窍是沿着树往回走,直到到达数组中的元素,然后您可以在目标中引用该索引。试试这个规范:

[
{
"operation": "shift",
"spec": {
"*": {
"Header": {
"recordNum": "[&2].recordNum",
"readOn": "[&2].&1.created_date_time",
"fileName": "[&2].&1.readFile"
},
"Data": {
"id": "[&2].&1.Id",
"first_name": "[&2].&1.First_Name",
"last_name": "[&2].&1.Last_Name"
}
}
}
}
]

关于apache-nifi - NiFi 中的 JoltTransformJSON 处理器(没有任何父标签的 json),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43466518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com