1

I have a problem sending JSON to the server and getting error in a specific case. I'm not sure if this is a frontend fix or backend, but couldn't find anything online on that.

In case I send:

CompanyName: "Bobs company"

request goes through, however if I send:

CompanyName: "Bob's company"

I get an error. Is there a way to fix that problem on frontend? I get the name by requesting value of the input :

  onChange={(e) => {
   setCompanyName(e.target.value);
  }}

Fillipo
  • 167
  • 2
  • 12

1 Answers1

1

The best way to fix your problem is to change the backend. If you need special characters escape them. In your case the JSON must look like this:

{"CompanyName": "Bob\'s company"}

Look into the answer from AlexB for more info: How to escape special characters in building a JSON string?

Nicolai Harms
  • 29
  • 1
  • 10