0

I am testing an application where I wish to input some text into a textfield and see if the application accepts it or raises an error. I am using postman and reading from a json data file with my different entries.

I wish to include an entry like thisL

{
  "name": "namewith\test",
},

However using this I get an error:

Unexpected control character at 1:25

I have tried this:

{
  "name": "namewith\\test",
},

this:

{
  "name": "namewith\/test",
},

this

 {
    "name": "namewith'\'test",
 },

How can I include this backslash and not have it recognized as an escape character?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
user1523236
  • 1,403
  • 3
  • 20
  • 43

2 Answers2

2

The correct way is \\

Your answer: { "name": "namewith\\test", },

should work. It works for me. Is there an object after this? That trailing comma could be a problem - unlike JS, JSON doesn't accept an extra comma at the end.

What error are you getting for this option.

Kevin
  • 359
  • 2
  • 7
  • 22
-1

May this idea help.

var customerData = document.getElementById("inputText").val();
var json = {
   name: customerData
}
var jsonString = JSON.stringify(json); //you get the content parsed
toto
  • 1,180
  • 2
  • 13
  • 30