I am grabbing a table on a workflow and send it to my webpage to be displayed, there are new lines and quotes etc in the text in my table and its causing my page to render weird and the json to be invalid, not sure how to fix this
// Example JSON string
const jsonString = `{{pageData.table}}`;
console.log(jsonString);
// Parse the JSON string
const data = JSON.parse(jsonString);
You probably need to use triple curly braces. By default, Handlebars escapes HTML characters.
In your case, you’ll need to use triple curly braces in both spots:
{
"table": "{{{tableEncoded}}}"
}
const jsonString = `{{{pageData.table}}}`;
1 Like
{
"table": "{{{tableEncoded}}}"
}
This results in an extra set of quotes. Try removing the surrounding quotes:
{
"table": {{{tableEncoded}}}
}
In reality, you can simplify this to just:
const jsonString = '{{{jsonEncode pageData.table}}}';
You don’t need to decode it in the workflow first. You can decode it with the helper.
It can be simplified even further since you’re immediately parsing the string back to an object:
const table = {{{jsonEncode pageData.table}}};
That results in a perfectly valid object - no need to parse it from a string.
1 Like
got it thanks!
page html/script
// Example JSON string
const table = {{{jsonEncode pageData.table}}};
console.log(table);
workflow endpoint reply node
{
"table": {{table.items}}
}
{
"table": {{table.items}}
}
This does not result in valid JSON, so not sure how it’s working. Is table.items
the array of rows directly from the Table: Get Node?
I would think you’d have to use:
{
"table": {{{jsonEncode table.items}}}
}
yes its the rows from the table
not sure if it is a janky solution but it does seem to be working