New lines "\n" in "table-view", but not in "json-view"?

How come I see new lines \n in “table-view”, but not in “json-view”?
I want to modify the JSON text to add line breaks in HTML (<br/>) where the \n are, but since it’s stripped out of the JSON I’m unsure how to go about that.

(The goal is to be able to add the text to a Webflow “Rich Text” field and get the different paragraphs, instead of everything on one long line like now.)

Table:
image

json:
image

Information on your n8n setup

  • n8n version: 1.0.5
  • Database: postgresql 15
  • Running n8n: docker
  • Operating system: Linux Debian 12

Looks like a bug. But would then only be in the view but would always execute 100% correctly.

As far as I can tell, it’s not there when the next node get the json. But not sure how to verify, other than my code does not work/find any new lines (\n).

Please post a workflow that reproduces that (newlines existing but then disappearing and so the replace not working). We can then have a look. Thanks!

Not totally sure how to do that best? It pulls the data from an API via HTTP request (output is JSON), but the data contains some personal information – so it’s not suited on a public forum. And if the goal is to have “untouched” data I’m not sure how to go about it.

What I see is that the table view consistently shows /n lines throughout the workflow, while the JSON view does not. And it seems like the JSON output (ie. $json.someid) also is missing the /n – so trying to manipulate the /n in the JSON data via i.e. a Code node, does not work.

The data is not extremely sensitive or anything, but not suitable here. I can give access individually to the instance if you want?

Update:

It seems like the \n gets added to the webflow cms item, but does not show on the final site. It’s apparently an existing bug.

I’m not sure about why I don’t see the \n json view, but it seems to go through. So I’m blaming webflow for not having sorted this out.

EDIT:
Solved my problem. I used a Code module to parse the json and replace the \n and swap it with <br /> – that seems to force Webflow to show line breaks (even if it shows correct with \n in the CMS, just not on the site).

This is the code I used:

// Loop through all items
const outputData = items.map((items, index) => {
  // Get the plain text from the input data
  const plainText = items.json.<key-that-has-text-with-newlines> || '';

  // Build the rich text format
  const richText = [
    {
      content: plainText.replace(/\n/g, '<br/>'), // Convert line breaks to <br> for rich text
      type: "paragraph",
    }
  ];

  // Add the parsed rich text to the output data with the new key "<key-that-has-text-with-newlines>-parsed"
  // (I want to keep the unmodified text also)
  return {
    json: {
      ...items.json, // Keep the existing JSON data
      "<key-that-has-text-with-newlines>-parsed": richText
    }
  };
});

// Output the modified items
return outputData;
2 Likes

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