Best answer

How to format plain text line breaks into html or something that doesn't break my json?

  • 29 June 2023
  • 4 replies

Userlevel 2
Badge +1

use case:

  • I have a webform sending plaintext data to a trigger my zap (webhooks by Zapier). 
  • I need to put that plaintext into the json body of an API Request for another system 
  • the webform has 8 plaintex fields


  • the webforms fields are large text areas, allowing for someone to insert a line break. 
  • the line breaks are messing up my json body for the API request

API request format:

"title": "title text from webform",
"content": "description text from webform"

What’s happening with the line breaks

"title": "title text from webform is working great (no line breaks)",
"content": "description text from webform is ruining things
because of this line break you see here"


If you put that into an online JSON Validator, you can see that the line break is breaking the string and ruining the key/value pair (did I use that right?) of “content” with the “{data from twebhe form}”, thus breaking the json formatting. 

line 4 should be in red as part of the string, but it’s not :( 



Question 1: So I know the problem, but what solutions do I have? 

I’ve been playing around with the Formatter, but not having a lot of luck. 

  • There are not actual line break characters to replace

  • The plaintext is not in markdown, so transforming from markdown to html doesn't’ give me the breaks 
    this transform inserts the <p> html, but no <br> even though there are breaks in the text


  • URL encoding is the closest i’ve gotten yet to creating an unbroken string, but i’m still running into to errors with my tests

Question 2: Is there a way to format 8 different fields in one or two steps? 

Let’s say that it can be solved by URL encode or something like that… do I have to add a formatter step for each field, or is there a way to format the initial webhook payload in fewer steps? 



Best answer by Troy Tessalone 29 June 2023, 22:41

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Userlevel 2
Badge +1

Update: the json format does work if i use the URL encode step from Formatter. The API request goes through. 🎉

However, that URL encoding is not the HTML code the other system wants to render. So when it renders the text, it’s with the URL encoding symbols, not the spaces, line breaks, etc. 😣

Assuming there’s another step I could do to format things correctly, that emphasizes the second part of my question. 16 steps (2 for each of the 8 fields) is a lot to run each time, especially when only necessary for submissions that include a line break. 

Userlevel 2
Badge +1

update 2: I have a workable solution for part 1 of my question, 3 formatter steps

  1. URL encode
  2. Replace %0D%0A with <br>
  3. URL decode

so I guess my core questions is now: is there a way to do this in fewer steps? either a better option that those 3 steps for each field (24 steps total) or by doing a transform for multiple fields in a single step? 


Userlevel 2
Badge +1

I should look more closely at the replace Zap help text


I can do it one step. 

I guess that leaves open the question if there’s a way to do multiple fields in a single transform. But, if not, I can live with this. 

Userlevel 7
Badge +14

Hi @ddpancratz 

Good question.

A Code step can be used to replace multiple Formatter steps.

Also, AI can be used.

Try Zap action: ChatGPT - Extract Structured Data