Reputation: 883
I have incoming JSON rows of data like,
{"signalName": "IU_BATT_ParkAssist", "msgId": 2268, "epoch": 1582322746, "usec": 376360, "vlan": "-1", "msgName": "EBS_Frame12", "vin": "000004", "value": 14.171869, "timestamp": 1582322746376}
I want the output to be modified to produce,
{"IU_BATT_ParkAssist":14.171869, "msgId": 2268, "epoch": 1582322746, "usec": 376360, "vlan": "-1", "msgName": "EBS_Frame12", "vin": "000004", "timestamp": 1582322746376}
The signalName and value keys were combined to make one new key:value pair with the key being the signalName and the value being the value field, "IU_BATT_ParkAssist":14.171869 along with the other original key, value pairs.
How can I achieve this in Nifi given that the signalName field will be dynamically changing in each row?
Upvotes: 2
Views: 323
Reputation: 31470
Try with below spec:
[
{
"operation": "shift",
"spec": {
"@(1,value)": "@(2,signalName)",
"*": "&"
}
},
{
"operation": "remove",
"spec": {
"signalName": "",
"value": ""
}
}
]
In shift operation we are combining signalName and value
.
In remove operation we are removing signalName and value
from our json
data.
Output:
{
"IU_BATT_ParkAssist" : 14.171869,
"msgId" : 2268,
"epoch" : 1582322746,
"usec" : 376360,
"vlan" : "-1",
"msgName" : "EBS_Frame12",
"vin" : "000004",
"timestamp" : 1582322746376
}
Upvotes: 2