跳到主要内容

删除消息属性值

删除控制流中 msg 的某个属性

问题背景

删除控制流中 msg 的某个属性

解决方案

使用 调整消息属性 节点删除 msg 的某个属性

示例

示例JSON

[{"id":"91cd2fa9.e0a96","type":"inject","z":"707b64edf9e06599","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":190,"y":180,"wires":[["54ec03e4.5714bc","243f5f973183da48"]]},{"id":"54ec03e4.5714bc","type":"change","z":"707b64edf9e06599","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":180,"wires":[["321900de.3cbea"]]},{"id":"321900de.3cbea","type":"debug","z":"707b64edf9e06599","logName":"删除后","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","logLevel":"info","dataType":"field","syntax":"mustache","template":"","x":580,"y":180,"wires":[]},{"id":"243f5f973183da48","type":"debug","z":"707b64edf9e06599","logName":"删除前","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","logLevel":"info","dataType":"field","format":"handlebars","syntax":"mustache","template":"输出日志: payload 值为 {{payload}}","output":"str","x":400,"y":120,"wires":[]}]

运行结果

点击注入按钮,触发消息,msg.payload 设置的是当前时间戳,通过 消息属性调整 节点,删除 msg.payload

高级技巧

思考一个问题:如何使用 调整消息属性 节点删除 msg 中的一个多层嵌套属性中的某个字段?

比如 msg 中有一个 content 字段,有如下属性, 如何删除 msg.content.params.deviceInfo 中的 ip 字段?

{
"params": {
"deviceInfo": {
"ip": "192.168.106.162",
"node": 1
},
"location": "shenzhen"
},
"datetime": "2025-09-05T06:24:56"
}

示例json,导入如下json,部署后点击注入按钮,查看结果

[{"id":"91cd2fa9.e0a96","type":"inject","z":"6000e185a1adf971","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"content","v":"{\"params\":{\"deviceInfo\":{\"ip\":\"192.168.106.98\",\"node\":1},\"location\":\"shenzhen\"},\"datetime\":\"2025-09-05T06:24:56\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":190,"y":880,"wires":[["54ec03e4.5714bc","243f5f973183da48","94d7d52d63dc744e"]]},{"id":"54ec03e4.5714bc","type":"change","z":"6000e185a1adf971","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":880,"wires":[["321900de.3cbea"]]},{"id":"321900de.3cbea","type":"debug","z":"6000e185a1adf971","logName":"删除后","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","logLevel":"info","dataType":"field","syntax":"mustache","template":"","x":580,"y":880,"wires":[]},{"id":"243f5f973183da48","type":"debug","z":"6000e185a1adf971","logName":"删除前","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","logLevel":"info","dataType":"field","format":"handlebars","syntax":"mustache","template":"输出日志: payload 值为 {{payload}}","output":"str","x":400,"y":820,"wires":[]},{"id":"94d7d52d63dc744e","type":"change","z":"6000e185a1adf971","name":"多层嵌套删除","rules":[{"t":"delete","p":"content.params.deviceInfo.ip","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":960,"wires":[["e367a09679ff8917"]]},{"id":"e367a09679ff8917","type":"debug","z":"6000e185a1adf971","logName":"日志输出","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","logLevel":"info","dataType":"field","format":"handlebars","syntax":"mustache","template":"输出日志: payload 值为 {{payload}}","output":"str","x":610,"y":960,"wires":[]}]

运行结果