Convert json to message text slack

I’m struggling to convert from json array to message text slack
I have default code node with this code

for (const item of $input.all()) {
  item.json.myNewField = 1;

return $input.all();

this code node is sending to slack node message text


i just drag and drop from code node json table, but the result in slack show [object Object],[object Object]

I don’t know how to convert this to text message slack.

PS: sorry for my format, I’m really newbie at programming and n8n

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hello @security_sec !
You can use Javascript method JSON.stringify to convert a JS Array to a readable JSON array.
Thus, if your variable loC contains an array that you would like to convert in text, simply do {{JSON.stringify($json.IoC)}} and that should do the trick.

However, to do that, you don’t especially need Code Node, just use a “Edit Field” node and use an expression in it.

I could help you firther if you give me a little bit more details about the structure of your input and what you want your Slack message to look like :slight_smile:

Hi Henri
The input is from HTTP request,

This is detail in the set node

This is detail in slack node

I’d like to have result for IoC is like this:

Using your {{JSON.stringify($json.IoC)}}
the result in slack is like this

Hello @security_sec,
Thanks for the précisons, by I am still not sure to understand the shape you want to give to your output Slack message.
On top of that, it seems n your object « IoC » is an array, so would you like to have one slack message per IoC object ?
The best would be to provide a written Slack message, the way you need it written and I’ll be able to give some help from that.


Hi Henri,

On top of that, it seems n your object « IoC » is an array, so would you like to have one slack message per IoC object ?

Yes, I’d like to have the result message per IoC or something like this:

indicator: eddb4476ca610f3c5e895f4811c9744704552d2f
type: FileHash-SHA1
created: 2023-12-07T15:08:58

Right now the result is hard to read:

[{“id”:3803084728,“indicator”:“100a5f3875e430f6de03d99752fbb6a7”,“type”:“FileHash-MD5”,“created”:“2023-12-07T15:08:58”,“content”:“”,“title”:“SUSP_ELF_LNX_UPX_Compressed_File”,“description”:“MD5 of ed38a61a6b7af436120465d352baa4cdf4ed8f01a7db7245b6254353e52f818f”,“expiration”:null,“is_active”:1,“role”:null},{“id”:3803084729,“indicator”:“5055925b5bcd715d5b70b57fdbeda66b”,“type”:“FileHash-MD5”,“created”:“2023-12-07T15:08:58”,“content”:“”,“title”:“is__elf”,“description”:“MD5 of b6db6702ca85bc80599d7f1d8b1a9b6dd56a8e87c55fc831dc9c689e54b8205d”,“expiration”:null,“is_active”:1,“role”:null},{“id”:3803084730,“indicator”:“051bc3273a20a53d730a3beaff2fadcd38d6bb85”,“type”:“FileHash-SHA1”,“created”:“2023-12-07T15:08:58”,“content”:“”,“title”:“SUSP_ELF_LNX_UPX_Compressed_File”,“description”:“SHA1 of ed38a61a6b7af436120465d352baa4cdf4ed8f01a7db7245b6254353e52f818f”,“expiration”:null,“is_active”:1,“role”:null},{“id”:3803084731,“indicator”:“eddb4476ca610f3c5e895f4811c9744704552d2f”,“type”:“FileHash-SHA1”,“created”:“2023-12-07T15:08:58”,“content”:“”,“title”:“is__elf”,“description”:“SHA1 of b6db6702ca85bc80599d7f1d8b1a9b6dd56a8e87c55fc831dc9c689e54b8205d”,“expiration”:null,“is_active”:1,“role”:null},{“id”:3803084732,“indicator”:“38ba7790697da0a736c80fd9a04731b8b0bac675cca065cfd42a56dde644e353”,“type”:“FileHash-SHA256”,“created”:“2023-12-07T15:08:58”,“content”:“”,“title”:“”,“description”:“”,“expiration”:null,“is_active”:1,“role”:null},

Thank you

Hello @security_sec,

Here is the kind of flow I would use for such things.
First, I split the elements inside your input array, and then, I send a Slack message for each of them.

The Manual trigger is a simulation of the HTTP Request that you are doing, so you should make sure the output of this node is well represented, remove the trigger, and place the two nodes after your HTTP Request node (You can remove the “Set” node).

Do not hesitate if there is something you don’t understand.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.