I have a simple question :
Using node-red, I have a result in this format: [{}], but I want it like this {}.
Could you please help me?
Thanks in advance.
I have a simple question :
Using node-red, I have a result in this format: [{}], but I want it like this {}.
Could you please help me?
Thanks in advance.
[{...}] is an array containing an object. {...} is an object. To go from [{}] to {}, simply index the first element like so:
result = [{"stuff": "things", ...}];
new_result = result[0];
new_result is {"stuff": "things", ...}
You can use the change node to extract the first element from an array using JSONATA.
[
2
e.g.
[{"id":"efe073293d865f28","type":"inject","z":"d8cb24f4281c772e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"id\":1,\"foo\":\"bar\"}]","payloadType":"json","x":190,"y":120,"wires":[["2f3f75244999adeb"]]},{"id":"2f3f75244999adeb","type":"change","z":"d8cb24f4281c772e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":120,"wires":[["78bf1271407b0e82"]]},{"id":"78bf1271407b0e82","type":"debug","z":"d8cb24f4281c772e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":120,"wires":[]}]