Issue with character when unmarshaling

(Miha) #1


When subject has something like " \ " (backslash) it will not unmarsh correctly this. How can I solve this issue.


type Ticket struct {
	Requestor    string `json:"requestor"`
	Subject      string `json:"subject"`
	Text         string `json:"text"`
	TelefonicaID string `json:"telefonicaid"`
	Circuitid    string `json:"circuitid"`

 err = json.Unmarshal(body, &t)

    if err != nil {


    w.Write([]byte("Wrong Json!"))


(Johan Dahl) #2


Is the backslash correctly used in the json you get? \n is newline \t tab and so on and \\ is just a backslash.

(Miha) #3


Just backslash in text, for exp for street address.

(Norbert Melzer) #4

Can you please show us the raw JSON (or a simplified version of it) that makes problems as well as the the value of err?

(Miha) #5

Hello guys

text in subject comes like:

{“requestor”:“”,“Subject”:“Test DE ESPA \321A, S.A.U 123321-SITEM-434343”,“Text”:“Pruebas API VENDOR Test”,“telefonicaid”:“INC000001069347”,“circuitid”: “12312321231”}

What I get from unmarshal is nothing, if there is " \ " in subject. If I remove it, then it will be ok and I will get data unmarshal. If I get some error? No, nothing, just data is not unamrshaled correctly.

(Norbert Melzer) #6

Yeah, that is invalid JSON, I’ll assume that the quotes are just replaced by the forum software, still you need to escape the backslash:

  "requestor": "",
  "Subject": "Test DE ESPA \\321A, S.A.U 123321-SITEM-434343",
  "Text": "Pruebas API VENDOR Test",
  "telefonicaid": "INC000001069347",
  "circuitid": "12312321231"

I’m pretty sure you will get somethin in err that is non-nil then…

invalid character ‘3’ in string escape code

(Miha) #7


not it is ok.

thank you for this!