Jolt 转换 - 单独分支中的匹配值 - JSON
Jolt Transformation - Match Values in Separate Branches - JSON
我想在 Nifi 中使用 Jolt 处理器实现以下 JSON 转换
输入JSON
{
"topLevel": {
"secondLevelA": {
"thirdLevelA": [
{
"norsemen": "huntinSouth",
"value": "AAA"
},
{
"norsemen": "huntinNorth",
"value": "BBB"
}
]
},
"secondLevelB": {
"thirdLevelB": [
{
"norsemen": "huntinNorth",
"oddCode": "AAA301"
},
{
"norsemen": "huntinNorth",
"oddCode": "BBB701"
},
{
"norsemen": "huntinWest",
"oddCode": "AAA701"
}
]
}
}
}
输出JSON
{
"NAME": [
{
"norsemen": "huntinSouth",
"value": "AAA",
"refValue": []
},
{
"norsemen": "huntinNorth",
"value": "BBB",
"refValue": [
{
"oddCode": [
"BBB701"
]
}
]
}
]
}
我想测试 secondLevelA.thirdLevelA.norsemen 和 secondLevelB.thirdLevelB.norsemen 之间的匹配。如果找到一个或多个匹配项,则包含在与匹配北欧人相同的集合中的所有 secondLevelB.thirdLevelB.oddCode 值将被放置在与相应匹配北欧人相同的集合中的输出中.
有没有办法使用现有的 Jolt 操作来做到这一点?
您似乎有一些非声明性逻辑,无法用 jolt 覆盖。
颠簸:
- 专注于转换 JSON 数据的结构,而不是操纵特定值
- 想法是:使用 Jolt 使大部分结构正确,然后编写代码来修复值
股票转换是:
shift : copy data from the input tree and put it the output tree
default : apply default values to the tree
remove : remove data from the tree
sort : sort the Map key values alphabetically ( for debugging and human readability )
cardinality : "fix" the cardinality of input data. Eg, the "urls" element is usually a List, but if there is only one, then it is a String
我在这里看不到 if/then/else
所以,我认为仅 jolt
无法完成您的任务
对我来说,最简单的方法是使用 JavaScript 或 Groovy 语言的脚本处理器。
我想在 Nifi 中使用 Jolt 处理器实现以下 JSON 转换
输入JSON
{
"topLevel": {
"secondLevelA": {
"thirdLevelA": [
{
"norsemen": "huntinSouth",
"value": "AAA"
},
{
"norsemen": "huntinNorth",
"value": "BBB"
}
]
},
"secondLevelB": {
"thirdLevelB": [
{
"norsemen": "huntinNorth",
"oddCode": "AAA301"
},
{
"norsemen": "huntinNorth",
"oddCode": "BBB701"
},
{
"norsemen": "huntinWest",
"oddCode": "AAA701"
}
]
}
}
}
输出JSON
{
"NAME": [
{
"norsemen": "huntinSouth",
"value": "AAA",
"refValue": []
},
{
"norsemen": "huntinNorth",
"value": "BBB",
"refValue": [
{
"oddCode": [
"BBB701"
]
}
]
}
]
}
我想测试 secondLevelA.thirdLevelA.norsemen 和 secondLevelB.thirdLevelB.norsemen 之间的匹配。如果找到一个或多个匹配项,则包含在与匹配北欧人相同的集合中的所有 secondLevelB.thirdLevelB.oddCode 值将被放置在与相应匹配北欧人相同的集合中的输出中.
有没有办法使用现有的 Jolt 操作来做到这一点?
您似乎有一些非声明性逻辑,无法用 jolt 覆盖。
颠簸:
- 专注于转换 JSON 数据的结构,而不是操纵特定值
- 想法是:使用 Jolt 使大部分结构正确,然后编写代码来修复值
股票转换是:
shift : copy data from the input tree and put it the output tree
default : apply default values to the tree
remove : remove data from the tree
sort : sort the Map key values alphabetically ( for debugging and human readability )
cardinality : "fix" the cardinality of input data. Eg, the "urls" element is usually a List, but if there is only one, then it is a String
我在这里看不到 if/then/else
所以,我认为仅 jolt
对我来说,最简单的方法是使用 JavaScript 或 Groovy 语言的脚本处理器。