颠簸转换-匹配单独分支中的值-JSON [英] Jolt Transformation - Match Values in Separate Branches - JSON

查看:101
本文介绍了颠簸转换-匹配单独分支中的值-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 值将与相应的匹配的准则在相同的集合中放置在输出中.

是否可以使用现有的摇动"操作来做到这一点?

解决方案

似乎您有一些无法用震撼力解决的非声明性逻辑.

从震动描述中:

震动:

  • 专注于转换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语言的脚本处理器.

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.

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

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