[英]How can I transform a JSON array of object contained in one message to multiple JSON object messages?
currently creating an ETL flow running in Node-RED, running on Node.js, running on Bluemix running on CloudFoundry. 当前正在创建在Node-RED中运行,在Node.js上运行,在CloudFoundry上运行的Bluemix上运行的ETL流。
I'm querying a Cloudant DB and get the result of the query returned as on single JSON array containing all documents as JSON objects. 我正在查询Cloudant数据库,并获得作为包含所有文档作为JSON对象的单个JSON数组返回的查询结果。
No I want to individually process those in a pipe-lined fashion. 不,我想以流水线方式单独处理那些。 How can this be archieved in Node-RED? 如何在Node-RED中归档?
Thanks a lot! 非常感谢!
JSON JSON格式
[{
"id": "c8342b2a.bf0df",
"type": "cloudant in",
"z": "2f0a54f6.110ccc",
"service": "nokeredrkie-cloudantNoSQLDB",
"cloudant": "",
"name": "",
"database": "tweets",
"search": "_all_",
"design": "",
"index": "",
"x": 295.70001220703125,
"y": 450.9333190917969,
"wires": [
["5e83a34.48cdd5c"]
]
}, {
"id": "c9411e75.2b1b7",
"type": "debug",
"z": "2f0a54f6.110ccc",
"name": "",
"active": true,
"console": "false",
"complete": "payload",
"x": 646.699951171875,
"y": 470.7333679199219,
"wires": []
}, {
"id": "3f1d2018.8f5ec8",
"type": "inject",
"z": "2f0a54f6.110ccc",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": true,
"x": 126.70001220703125,
"y": 472.6666564941406,
"wires": [
["c8342b2a.bf0df"]
]
}, {
"id": "5e83a34.48cdd5c",
"type": "function",
"z": "2f0a54f6.110ccc",
"name": "",
"func": "//msg.payload = JSON.parse(msg.payload);\nmsg.payload = msg.payload[1].tweet.user.screen_name;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 444.70001220703125,
"y": 489.4000549316406,
"wires": [
["c9411e75.2b1b7"]
]
}]
Output the Cloudant node to Function node with something like this: 将Cloudant节点输出到Function节点 ,如下所示:
var msgs = [];
for (var i = 0; i< msg.payload.length; i++) {
msgs.push({payload: msg.payload[i]});
}
return [msgs]
This will stream each item in the array to the next node in the flow 这会将数组中的每个项目流式传输到流中的下一个节点
Edit: need to wrap the array in another set of [] to get all the messages out the same output. 编辑:需要将数组包装在另一套[]中,以使所有消息都来自同一输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.