1

我想在 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.norsemensecondLevelB.thirdLevelB.norsemen的值之间的匹配。如果找到一个或多个匹配项,则包含在与匹配的norsemen 相同的集合中的所有 secondLevelB.thirdLevelB.oddCode 值被放置在与相应匹配的norsemen 相同的集合中的输出中。

有没有办法使用现有的 Jolt Operations 来做到这一点?

4

1 回答 1

0

似乎您有一些无法用 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 语言的脚本处理器。

于 2017-05-26T09:19:28.487 回答