Nifi JoltTransformJSON:将下划线标记为密钥名称

时间:2018-03-08 16:58:09

标签: apache-nifi jolt

我正在尝试在Apache Nifi中编写一个转换json格式的jolt。我设法转换了摇晃但是一个属性缺少下划线:

输出:

          {
     "Source": {   //source is missing underscore. It should look like _Source
           "userName": "Lulu"
      }
  }

我的输入如下:

     {
        "user_name": "Lulu"
     }

目前我的jolt表达式如下:

[
        {
          "operation": "shift",
          "spec": {
               "user_name":"userName"
           }
        },
        {
          "operation": "modify-overwrite-beta",
          "spec": {         
              "_Source":{
                  "userName":"@(2,userName)"
               }
           }
         },
         { "operation": "remove", 
          "spec": { 

                    "userName": "" } 
               }
]

如何保留下划线登录属性"来源"?

我被困在弄清楚这一部分。我想知道我在jolt表达式中缺少什么。提前谢谢,伙计们

2 个答案:

答案 0 :(得分:3)

我认为下划线可能是该运算符中的某种特殊字符,在_Source前面尝试双反斜杠:

[
  {
    "operation": "shift",
    "spec": {
      "user_name": "userName"
    }
        },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "\\_Source": {
        "userName": "@(2,userName)"
      }
    }
         },
  {
    "operation": "remove",
    "spec": {
      "userName": ""
    }
  }
]

答案 1 :(得分:1)

只需一次"转移"

即可

规格

[
  {
    "operation": "shift",
    "spec": {
      "user_name": "_Source.userName"
    }
  }
]