Jolt 转换 - 匹配不同分支中的值 - JSON [英] Jolt Transformation - Match Values in Separate Branches - JSON

查看:36
本文介绍了Jolt 转换 - 匹配不同分支中的值 - JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Nifi 中使用 Jolt 处理器实现以下 JSON 转换

输入 JSON

<代码>{顶层": {secondLevelA":{第三层A":[{"norsemen": "huntinSouth",价值":AAA"},{"norsemen": "huntinNorth",价值":BBB"}]},secondLevelB":{第三层B":[{"norsemen": "huntinNorth","oddCode": "AAA301"},{"norsemen": "huntinNorth","oddCode": "BBB701"},{"norsemen": "huntinWest","oddCode": "AAA701"}]}}}

输出 JSON

<代码>{姓名": [{"norsemen": "huntinSouth",价值":AAA",参考值":[]},{"norsemen": "huntinNorth","value": "BBB",参考值":[{奇数":[BBB701"]}]}]}

我想测试 secondLevelA.thirdLevelA.norsemensecondLevelB.thirdLevelB.norsemen 的值之间的匹配.如果找到一个或多个匹配项,则包含在与匹配的挪威人相同的集合中的 secondLevelB.thirdLevelB.oddCode 的所有值都将被放置在与相应匹配的挪威人相同的集合中的输出中.>

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

解决方案

似乎您有一些无法用 jolt 覆盖的非声明性逻辑.

来自 jolt 描述:

震动:

  • 专注于转换 JSON 数据的结构,而不是操作特定值
    • 想法是:使用 Jolt 使大部分结构正确,然后编写代码来修复值

Stock 转换是:

shift : 从输入树复制数据并将其放入输出树default : 将默认值应用于树remove : 从树中删除数据sort :按字母顺序对 Map 键值进行排序(用于调试和人类可读性)cardinality :修复"输入数据的基数.例如,urls"元素通常是一个列表,但如果只有一个,那么它是一个字符串

<小时>

我在这里看不到那种if/then/else

所以,我认为你的任务不能只用 jolt

对我来说,最简单的方法是使用 JavaScript 或 Groovy 语言的脚本处理器.

I want to achieve the following JSON transformation using Jolt processor in Nifi

Input 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"
                }
            ]
        }
    }
}

Output JSON

{
    "NAME": [
        {
            "norsemen": "huntinSouth",
            "value": "AAA",
            "refValue": []
        },
        {
            "norsemen": "huntinNorth",
            "value": "BBB",
            "refValue": [
                {
                    "oddCode": [
                        "BBB701"
                    ]
                }
            ]
        }
    ]
}

I would like to test for matches between the values of secondLevelA.thirdLevelA.norsemen and secondLevelB.thirdLevelB.norsemen. If one or more matches is found, all values of secondLevelB.thirdLevelB.oddCode contained in the same set as the matching norsemen would be placed in the output in the same set as the corresponding matching norsemen.

Is there a way to do this using existing Jolt Operations?

解决方案

seems you have some non-declarative logic that could not be covered with jolt.

From jolt description:

Jolt :

  • focuses on transforming the structure of your JSON data, not manipulating specific values
    • The idea being: use Jolt to get most of the structure right, then write code to fix values

The Stock transforms are:

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


I don't see here kind of if/then/else

So, I think your task could not be covered with just jolt

for me the easiest way will be script processor with JavaScript or Groovy language.

这篇关于Jolt 转换 - 匹配不同分支中的值 - JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆