Slack Message Type Block ERROR: Unexpected token in JSON

Describe the problem/error/question

Slack Message Type Block, issue with json parsing but not sure best way to work around

What is the error message (if any)?

{
“type”: “section”,
“text”: {
“type”: “mrkdwn”,
“text”: “{{ $json[“orderItems”].join(”\n") }}"
}
}
ERROR: Unexpected token in JSON at position 606

the join is causing me problems but I need the join to prevent slack from spamming messages over and over for each item. Not sure best way to fix as its adding newlines as well as the \n
{
“type”: “section”,
“text”: {
“type”: “mrkdwn”,
“text”: “sampletext
sampletext”
}
}

Hey @CameronBarrass,

Welcome to the community :raised_hands:

Can you share the full json you are sending?

Sure

So I have had to remove the spreadsheet info as it contains personal information however the spreadsheet contains item sales data directly from our magento store
so examples of items are below,

name
Pokemon - Scarlet & Violet - Base Set - Booster Pack
Pokemon - Sun & Moon - Miracle Twins - Japanese Booster Pack
Free Sweets
Pokemon Sticker
Yu-Gi-Oh! - 2-Player Starter Set
Yu-Gi-Oh! Sticker
Free Sweets
Keyring
Pokemon - Holiday Calendar 2023
Keyring
Pokemon Sticker
Free Haribo

and I am trying to use a .join so slack doesnt message for each item individually.

This workflow works fine for a normal slack message, but the issue is coming from me trying to use similar in a message block in slack to try and make the messages look nicer

Above is an image of what the output looks like but i was trying to get something similar with blocks that looks like

image
The coming soon would have the same information as previous image

So I ran into a similar issue when creating a product sync thing between the TikTok Shop and our Ecommerce platform. I was struggling to submit the JSON of the product description as it contained new lines and </p> tags and stuff.

The solution to this which also fixed this Slack issue I was having was the following

{
			"type": "section",
			"text": {
				"type": "mrkdwn",
				"text": {{  JSON.stringify($json["orderItems"].join('\n')) }}
			}

JSON.stringify( $value )

This will fix all your problems, just make sure to remove the “” around it as the stringify does this for you. If you dont you will get errors

:v:

1 Like

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