[英]Nifi JoltTransformJSON spec for concatenating values based on condition
I have json input of form as shown below.我有 json 的表单输入,如下所示。 It can also be empty like
[]
也可以为空,如
[]
[
{
"NAME": "Aron",
"CITY": "NewYork",
"PROV": "NY",
"POSTALCODE": "12345",
"DATE": "2021-08-19",
"TIME": "14:25:25"
},
{
"NAME": "Paul",
"CITY": "Chicago",
"PROV": "BI",
"POSTALCODE": null,
"DATE": "2021-08-19",
"TIME": ""
}
]
I am writing NiFi JoltTransformJSON spec so my output will contain the JSON as我正在编写 NiFi JoltTransformJSON规范,所以我的 output 将包含 JSON 作为
[
{
"NAME" : "Aron",
"Address" : "NewYork, NY, Pin: 12345",
"DATE" : "2021-08-19",
"TIME" : "14:25:25"
},
{
"NAME" : "Paul",
"Address" : "Chicago, BI",
"DATE" : "2021-08-19",
"TIME" :""
}
]
Basically it merges City , Prov , Postalcode and puts in new key Address .基本上它合并了City 、 Prov 、 Postalcode并放入新的密钥Address 。 They are concatenated using, comma between them and also if Postalcode is not null it is concatenated in Address as Pin:.
它们之间使用逗号连接,如果邮政编码不是null ,则在地址中连接为 Pin:。 If everything ( City , Prov , Postalcode ) is null then Address will be empty like
"Address":""
如果一切(城市,省,邮政编码)是null那么地址将是空的,如
"Address":""
I am trying with shift followed by remove我正在尝试 shift 然后删除
[
{
"operation": "shift",
"spec": {
"@(1,CITY)": "",
"*": "&"
}
},
{
"operation": "remove",
"spec": {
"CITY": "",
"PROV": "",
"POSTALCODE" : "",
}
}
]
I have achieved this using SplitJSON , EvaluateJSONPath and UpdateAttribute .我已经使用SplitJSON 、 EvaluateJSONPath和UpdateAttribute实现了这一点。 But I am trying this using JoltTransformJSON now.
但我现在正在尝试使用JoltTransformJSON 。 Is this achievable using JoltTransformJSON ?
这可以使用JoltTransformJSON实现吗?
You can consecutively use modify-overwrite-beta along with concat and size functions and shift transformations such that您可以连续使用modify-overwrite-beta以及concat和size函数以及移位转换,这样
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*":{
"Address1": "=concat(@(1,CITY),',',@(1,PROV))",
"Address2": "=concat(',Pin:',@(1,POSTALCODE))",
"Addr2Size": "=size(@(1,Address2))",
"Address": "=concat(@(1,Address1),@(1,Address2))"
}
}
},
{
"operation": "shift",
"spec": {
"*":{
"NAME": "[&1].&",
"Addr2Size": {
"5": {
"@(2,Address1)": "[&3].Address"
},
"*": {
"@(2,Address)": "[&3].Address"
}
},
"DATE": "[&1].&",
"TIME": "[&1].&"
}
}
}
]
where size function is used to determine whether POSTALCODE value is null or not .其中size function 用于判断POSTALCODE值是否为null 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.