NiFi - JOLT 规范添加自定义字段
NiFi - JOLT Spec add custom field
我需要 JOLT 规范方面的帮助,我在 JOLT 表达式语言方面没有经验,为了达到这一点,用 JOLT 规范扁平化 JSON 响应花了我很长时间。
我需要添加一个不在 JSON 响应中的变量 我尝试使用 "dev_id" : "TEST HELLO".
我正在使用 https://jolt-demo.appspot.com/#inception 来测试我添加 dev_id" : "TEST HELLO" 的 JOLT 规范,但我在输出中找不到 dev_id 并且没有语法错误.
提前致谢。
我的 JSON 回复如下所示:
{
"id": 25692584,
"timestamp": "2018-11-19T07:23:07.022916",
"notification": "$device-add",
"parameters": {
"id": "aa190000-3143-0000-2020",
"isBlocked": false,
"name": "aa190000-3143-0000-2020",
"status": "Online",
"type": "DOOR",
"time": "2000-01-01T02:00:39.000000",
"secure": true,
"mode": "idle",
"gps.lat": 24.675699,
"gps.long": 46.663898,
"entries": "959,reboot 0x0001",
"data": {
"desc": "Undescribed",
"imei": "861107036",
"simid": "89564700000"
},
"network": {
"id": 11,
"name": "TEST",
"description": null
},
"deviceClass": {
"id": 12,
"name": "CGM_IOT",
"version": "2.0",
"isPermanent": false,
"offlineTimeout": 60,
"data": null,
"equipment": []
}
}
}
然后我使用以下 JOLT 规范:
[
{
"operation": "shift",
"spec": {
"*": "&",
"parameters": {
"*": "parameters-&",
"data": {
"*": "data-&"
},
"network": {
"*": "network-&"
},
"deviceClass": {
"*": "deviceClass-&"
}
}
}
}
]
并收到以下输出:
{
"id" : 25692584,
"timestamp" : "2018-11-19T07:23:07.022916",
"notification" : "$device-add",
"parameters-id" : "aa190000-3143-0000-2020",
"parameters-isBlocked" : false,
"parameters-name" : "aa190000-3143-0000-2020",
"parameters-status" : "Online",
"parameters-type" : "DOOR",
"parameters-time" : "2000-01-01T02:00:39.000000",
"parameters-secure" : true,
"parameters-mode" : "idle",
"parameters-gps.lat" : 24.675699,
"parameters-gps.long" : 46.663898,
"parameters-entries" : "959,reboot 0x0001",
"data-desc" : "Undescribed",
"data-imei" : "861107036",
"data-simid" : "89564700000",
"network-id" : 11,
"network-name" : "TEST",
"network-description" : null,
"deviceClass-id" : 12,
"deviceClass-name" : "CGM_IOT",
"deviceClass-version" : "2.0",
"deviceClass-isPermanent" : false,
"deviceClass-offlineTimeout" : 60,
"deviceClass-data" : null,
"deviceClass-equipment" : [ ]
}
我在 JOLT 规范中尝试过的内容:
[
{
"operation": "shift",
"spec": {
"*": "&",
"dev_id": "TEST HELLO",
"parameters": {
"*": "parameters-&",
"data": {
"*": "data-&"
},
"network": {
"*": "network-&"
},
"deviceClass": {
"*": "deviceClass-&"
}
}
}
}
]
我的预期输出:
{
"id" : 25692584,
"timestamp" : "2018-11-19T07:23:07.022916",
"notification" : "$device-add",
"dev_id" : "TEST HELLO",
"parameters-id" : "aa190000-3143-0000-2020",
"parameters-isBlocked" : false,
"parameters-name" : "aa190000-3143-0000-2020",
"parameters-status" : "Online",
"parameters-type" : "DOOR",
"parameters-time" : "2000-01-01T02:00:39.000000",
"parameters-secure" : true,
"parameters-mode" : "idle",
"parameters-gps.lat" : 24.675699,
"parameters-gps.long" : 46.663898,
"parameters-entries" : "959,reboot 0x0001",
"data-desc" : "Undescribed",
"data-imei" : "861107036",
"data-simid" : "89564700000",
"network-id" : 11,
"network-name" : "TEST",
"network-description" : null,
"deviceClass-id" : 12,
"deviceClass-name" : "CGM_IOT",
"deviceClass-version" : "2.0",
"deviceClass-isPermanent" : false,
"deviceClass-offlineTimeout" : 60,
"deviceClass-data" : null,
"deviceClass-equipment" : [ ]
}
在轮班"values are the keys"和"keys are the values"期间,您可以使用#将值设置为常量:
[
{
"operation": "shift",
"spec": {
"*": "&",
"#TEST HELLO": "dev_id",
"parameters": {
"*": "parameters-&",
"data": {
"*": "data-&"
},
"network": {
"*": "network-&"
},
"deviceClass": {
"*": "deviceClass-&"
}
}
}
}
]
我需要 JOLT 规范方面的帮助,我在 JOLT 表达式语言方面没有经验,为了达到这一点,用 JOLT 规范扁平化 JSON 响应花了我很长时间。
我需要添加一个不在 JSON 响应中的变量 我尝试使用 "dev_id" : "TEST HELLO".
我正在使用 https://jolt-demo.appspot.com/#inception 来测试我添加 dev_id" : "TEST HELLO" 的 JOLT 规范,但我在输出中找不到 dev_id 并且没有语法错误.
提前致谢。
我的 JSON 回复如下所示:
{
"id": 25692584,
"timestamp": "2018-11-19T07:23:07.022916",
"notification": "$device-add",
"parameters": {
"id": "aa190000-3143-0000-2020",
"isBlocked": false,
"name": "aa190000-3143-0000-2020",
"status": "Online",
"type": "DOOR",
"time": "2000-01-01T02:00:39.000000",
"secure": true,
"mode": "idle",
"gps.lat": 24.675699,
"gps.long": 46.663898,
"entries": "959,reboot 0x0001",
"data": {
"desc": "Undescribed",
"imei": "861107036",
"simid": "89564700000"
},
"network": {
"id": 11,
"name": "TEST",
"description": null
},
"deviceClass": {
"id": 12,
"name": "CGM_IOT",
"version": "2.0",
"isPermanent": false,
"offlineTimeout": 60,
"data": null,
"equipment": []
}
}
}
然后我使用以下 JOLT 规范:
[
{
"operation": "shift",
"spec": {
"*": "&",
"parameters": {
"*": "parameters-&",
"data": {
"*": "data-&"
},
"network": {
"*": "network-&"
},
"deviceClass": {
"*": "deviceClass-&"
}
}
}
}
]
并收到以下输出:
{
"id" : 25692584,
"timestamp" : "2018-11-19T07:23:07.022916",
"notification" : "$device-add",
"parameters-id" : "aa190000-3143-0000-2020",
"parameters-isBlocked" : false,
"parameters-name" : "aa190000-3143-0000-2020",
"parameters-status" : "Online",
"parameters-type" : "DOOR",
"parameters-time" : "2000-01-01T02:00:39.000000",
"parameters-secure" : true,
"parameters-mode" : "idle",
"parameters-gps.lat" : 24.675699,
"parameters-gps.long" : 46.663898,
"parameters-entries" : "959,reboot 0x0001",
"data-desc" : "Undescribed",
"data-imei" : "861107036",
"data-simid" : "89564700000",
"network-id" : 11,
"network-name" : "TEST",
"network-description" : null,
"deviceClass-id" : 12,
"deviceClass-name" : "CGM_IOT",
"deviceClass-version" : "2.0",
"deviceClass-isPermanent" : false,
"deviceClass-offlineTimeout" : 60,
"deviceClass-data" : null,
"deviceClass-equipment" : [ ]
}
我在 JOLT 规范中尝试过的内容:
[
{
"operation": "shift",
"spec": {
"*": "&",
"dev_id": "TEST HELLO",
"parameters": {
"*": "parameters-&",
"data": {
"*": "data-&"
},
"network": {
"*": "network-&"
},
"deviceClass": {
"*": "deviceClass-&"
}
}
}
}
]
我的预期输出:
{
"id" : 25692584,
"timestamp" : "2018-11-19T07:23:07.022916",
"notification" : "$device-add",
"dev_id" : "TEST HELLO",
"parameters-id" : "aa190000-3143-0000-2020",
"parameters-isBlocked" : false,
"parameters-name" : "aa190000-3143-0000-2020",
"parameters-status" : "Online",
"parameters-type" : "DOOR",
"parameters-time" : "2000-01-01T02:00:39.000000",
"parameters-secure" : true,
"parameters-mode" : "idle",
"parameters-gps.lat" : 24.675699,
"parameters-gps.long" : 46.663898,
"parameters-entries" : "959,reboot 0x0001",
"data-desc" : "Undescribed",
"data-imei" : "861107036",
"data-simid" : "89564700000",
"network-id" : 11,
"network-name" : "TEST",
"network-description" : null,
"deviceClass-id" : 12,
"deviceClass-name" : "CGM_IOT",
"deviceClass-version" : "2.0",
"deviceClass-isPermanent" : false,
"deviceClass-offlineTimeout" : 60,
"deviceClass-data" : null,
"deviceClass-equipment" : [ ]
}
在轮班"values are the keys"和"keys are the values"期间,您可以使用#将值设置为常量:
[
{
"operation": "shift",
"spec": {
"*": "&",
"#TEST HELLO": "dev_id",
"parameters": {
"*": "parameters-&",
"data": {
"*": "data-&"
},
"network": {
"*": "network-&"
},
"deviceClass": {
"*": "deviceClass-&"
}
}
}
}
]